title: undefined index error in php- android
body: <p>I m getting this undefined index error on my localhost browser and invalid ip address on my app while running this function .  </p>
  
  <blockquote>
    <p>Notice: Undefined index: name in C:\xampp\htdocs\prateek\insert.php on line 10<br>
    Notice: Undefined index: gender in C:\xampp\htdocs\prateek\insert.php on line 11<br>
    Notice: Undefined index: mobno in C:\xampp\htdocs\prateek\insert.php on line 12<br>
    Notice: Undefined index: dob in C:\xampp\htdocs\prateek\insert.php on line 13<br>
    Notice: Undefined index: tob in C:\xampp\htdocs\prateek\insert.php on line 14<br>
    Notice: Undefined index: msg in C:\xampp\htdocs\prateek\insert.php on line 15<br>
    Notice: Undefined index: pob in C:\xampp\htdocs\prateek\insert.php on line 16<br>
    Notice: Undefined index: email in C:\xampp\htdocs\prateek\insert.php on line 17
    {"code":0}</p>
  </blockquote>
  
  <pre><code>&lt;?php   $host='127.0.0.1';
  $uname='root';  $pwd='Hunch@123';   $db="astro";
  
  $con = mysql_connect($host,$uname,$pwd) or die("connection
     failed");    mysql_select_db($db,$con) or die("db selection failed");
     $queryresult = array();  $name=$_REQUEST['name'];    $gender=$_REQUEST['gender'];
     $mobno=$_REQUEST['mobno'];   $dob=$_REQUEST['dob'];  $tob=$_REQUEST['tob'];  $msg=$_REQUEST['msg'];
  $pob=$_REQUEST['pob'];  $email=$_REQUEST['email'];  $flag['code']=0;
  
  if($r=mysql_query("insert into
     kundali(gender,name,email,d_o_b,t_o_b,p_o_b,mobil_no,message)
     values('$gender','$name','$email','$dob','$tob','$pob','$mobno','$msg')
     ",$con))     {       $flag['code']=1;        echo"hi";   }
  
  print(json_encode($flag));  mysql_close($con); ?&gt;
  </code></pre>
  
  <ol>
  <li><pre><code>public void insert()
     {
         ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
  
         nameValuePairs.add(new BasicNameValuePair("name",name));
         nameValuePairs.add(new BasicNameValuePair("gender",gender));
         nameValuePairs.add(new BasicNameValuePair("mobno",mobno));
         nameValuePairs.add(new BasicNameValuePair("email",email));
         nameValuePairs.add(new BasicNameValuePair("dob",dob));
         nameValuePairs.add(new BasicNameValuePair("tob",tob));
         nameValuePairs.add(new BasicNameValuePair("pob",pob));
         nameValuePairs.add(new BasicNameValuePair("msg",msg));
         try
         {
             HttpClient httpclient = new DefaultHttpClient();
             HttpPost httppost = new HttpPost("http://localhost/prateek/insert.php");
             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             HttpResponse response = httpclient.execute(httppost);
             HttpEntity entity = response.getEntity();
             is = entity.getContent();
             Log.e("pass 1", "connection success ");
         }
         catch(Exception e)
         {
             Log.e("Fail 1", e.toString());
             Toast.makeText(getApplicationContext(), "Invalid IP Address",
                     Toast.LENGTH_LONG).show();
         }
  
         try
         {
             BufferedReader reader = new BufferedReader
                     (new InputStreamReader(is,"iso-8859-1"),8);
             StringBuilder sb = new StringBuilder();
             while ((line = reader.readLine()) != null)
             {
                 sb.append(line + "\n");
             }
             is.close();
             result = sb.toString();
             Log.e("pass 2", "connection success ");
         }## Heading ##
         catch(Exception e)
         {
             Log.e("Fail 2", e.toString());
         }
  
         try
         {
             JSONObject json_data = new JSONObject(result);
             code=(json_data.getInt("code"));
  
             if(code==1)
             {
                 Toast.makeText(getBaseContext(), "Inserted Successfully",
                         Toast.LENGTH_SHORT).show();
             }
             else
             {
                 Toast.makeText(getBaseContext(), "Sorry, Try Again",
                         Toast.LENGTH_LONG).show();
             }
         }
         catch(Exception e)
         {
             Log.e("Fail 3", e.toString());
         }
     }
  </code></pre></li>
  </ol>