-1

Error Which am facing with my php code :-

    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

The following is the java code for passing the value to .php file:

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);
}

The following is my php code.Where I am accepting values from my android app.

 <?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);
 ?>

Please Suggest me on How to fix the problem ?.

Aravind
  • 11
  • 7
  • So what is your question here? The reason for the notice you get is explained in about 53492649263484 answers alone here on StackOverflow: The `$_GET` array simply does not have such keys which means they were not sent. – arkascha Mar 06 '16 at 08:49
  • And a side note: you want to read about "sql injection vulnerability" and how to prevent it by using "prepared statements" and " parameter binding". – arkascha Mar 06 '16 at 08:50
  • can u pls post the solution here – Aravind Mar 06 '16 at 08:50
  • 1
    No, since there is no "solution" for your question. If you do not send those parameters which is obvious, since they are not received, how should this issue get resolved? Obviously by sending the parameters which is nothing we can do for you. – arkascha Mar 06 '16 at 08:52
  • @arkascha pls see the edit... – Aravind Mar 06 '16 at 12:34

1 Answers1

0

Basically the $_GET variables you want to use are not set. To be sure the app passes the right variables use var_dump($_GET); to see what variables it passes on.

For more information about your error see: php notice undefined variable and notice undefined index

Community
  • 1
  • 1
Fin
  • 386
  • 1
  • 15