首页 文章

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

提问于
浏览
0

我在运行此功能时在我的本地主机浏览器上获取此未定义的索引错误,并在我的应用程序上无效的IP地址 .

注意:未定义的索引:第10行的C:\ xampp \ htdocs \ prateek \ insert.php中的名称注意:未定义的索引:第11行的C:\ xampp \ htdocs \ prateek \ insert.php中的性别注意:未定义的索引:第12行的C:\ xampp \ htdocs \ prateek \ insert.php中的mobno注意:未定义的索引:第13行的C:\ xampp \ htdocs \ prateek \ insert.php中的dob注意:未定义的索引:C:\ xampp中的tob第14行的\ htdocs \ prateek \ insert.php注意:未定义的索引:第15行的C:\ xampp \ htdocs \ prateek \ insert.php中的msg注意:未定义的索引:C:\ xampp \ htdocs \ prateek \ insert中的pob第16行的.php注意:未定义的索引:第17行的C:\ xampp \ htdocs \ prateek \ insert.php中的电子邮件{“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); ?>
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 + "\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());
       }
   }

1 回答

  • 0

    1- Invalid IP address solve:

    更改此行中的网址

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

    至:

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

    2- Notice: Undefined index... Error: 您需要以与在PHP代码中阅读它们相同的方式发送参数(名称,性别,...),

    例如,如果你的PHP代码中你将它们读作 $_POST['name'] ,那么你需要将它们作为POST发送,如果 $_GET['name'] 然后将它们作为GET发送

相关问题