php- android中未定义的索引错误

I m getting this undefined index error on my localhost browser and invalid ip address on my app while running this function .

Notice: Undefined index: name in C:\xampp\htdocs\prateek\insert.php on line 10
Notice: Undefined index: gender in C:\xampp\htdocs\prateek\insert.php on line 11
Notice: Undefined index: mobno in C:\xampp\htdocs\prateek\insert.php on line 12
Notice: Undefined index: dob in C:\xampp\htdocs\prateek\insert.php on line 13
Notice: Undefined index: tob in C:\xampp\htdocs\prateek\insert.php on line 14
Notice: Undefined index: msg in C:\xampp\htdocs\prateek\insert.php on line 15
Notice: Undefined index: pob in C:\xampp\htdocs\prateek\insert.php on line 16
Notice: Undefined index: email in C:\xampp\htdocs\prateek\insert.php on line 17 {"code":0}

<?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); ?>
  1. public void insert()
       {
           ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    
           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 + "
    ");
               }
               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());
           }
       }
    

1- Invalid IP address solve:

change the URL in this line

HttpPost httppost = new HttpPost("http://localhost/prateek/insert.php");

to:

HttpPost httppost = new HttpPost("http://IP_OF_SERVER/prateek/insert.php");

2- Notice: Undefined index... Error: you need to send the parameters (name, gender, ...) the same way you read them in your PHP code,

ex, if in your PHP code you read them as $_POST['name'], then you need to send them as POST, and if $_GET['name'] then send them as GET