【问题标题】:Undefined index: in php code (xampp)未定义索引:在 php 代码中 (xampp)
【发布时间】:2016-06-19 21:20:04
【问题描述】:

我的 php 代码面临的错误:-

    Notice: Undefined index: latitude in C:\xampp1\htdocs\tutorialspoint\pass.php on line 9
    Notice: Undefined index: longitude in C:\xampp1\htdocs\tutorialspoint\pass.php on line 10
     success

以下是将值传递给.php文件的java代码:

public void writePost(double latitude,double longitude){


    String urlSuffix = "&latitude="+latitude+"&longitude="+longitude;
    class RegisterUser extends AsyncTask<String, Void, String> {




        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

        }

        @Override
        protected String doInBackground(String... params) {
            String s = params[0];
            BufferedReader bufferedReader = null;
            try {
                URL url = new URL(GETWRITE_URL+s); //getwriteurl= url of ur php uptop .php
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setDoInput(true);
                bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

                String result;

                result = bufferedReader.readLine();
                return result;
            }catch(Exception e){
                return null;
            }
        }
    }

    RegisterUser ru = new RegisterUser();
    ru.execute(urlSuffix);
}

以下是我的 php 代码。我在哪里接受来自我的 android 应用程序的值。

 <?php
 $con=mysqli_connect("localhost","******","******","route69");

 if (mysqli_connect_errno($con))
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

 $latitude = $_GET['latitude']; // accepting the current latitude from android app
 $longitude = $_GET['longitude'];//accepting the current longitude from android app
 $check = "INSERT INTO taxi1(Latitude, Longitude) values('$latitude','$longitude')";
 $result = mysqli_query($con,$check);

 if(isset($result)){
 echo "success";
 } else {
 echo "failed";
 }
 mysqli_close($con);
 ?>

请建议我如何解决这个问题?

【问题讨论】:

  • 那么您的问题是什么?您收到通知的原因仅在 StackOverflow 上的大约 53492649263484 个答案中进行了解释:$_GET 数组根本没有这样的键,这意味着它们没有被发送。
  • 附注:您想了解“sql 注入漏洞”以及如何使用“准备好的语句”和“参数绑定”来防止它。
  • 你可以在这里发布解决方案
  • 不,因为您的问题没有“解决方案”。如果你不发送那些明显的参数,因为它们没有收到,这个问题应该如何解决?显然,通过发送参数我们无能为力。
  • @arkascha 请查看编辑...

标签: java php android android-asynctask xampp


【解决方案1】:

基本上没有设置您要使用的$_GET 变量。 为确保应用传递正确的变量,请使用var_dump($_GET); 查看它传递的变量。

有关您的错误的更多信息,请参阅:php notice undefined variable and notice undefined index

【讨论】:

  • 要么解释答案,要么不发表解决方案,发表评论。
猜你喜欢
  • 2014-08-11
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
  • 1970-01-01
  • 2018-11-26
  • 2015-04-09
  • 2013-01-26
相关资源
最近更新 更多