2016-03-06 34 views
-1

錯誤,我有我的PHP代碼面向: -未定義指數:在PHP代碼(XAMPP)

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

請建議我如何解決這個問題?

+0

那麼,什麼是你的問題嗎?你得到的通知的原因在StackOverflow中僅在這裏解釋了53492649263484個答案:'$ _GET'數組根本沒有這樣的密鑰,這意味着它們沒有被髮送。 – arkascha

+0

另一方面:您想了解「sql注入漏洞」以及如何使用「準備好的語句」和「參數綁定」來防止它。 – arkascha

+0

你可以在這裏發佈解決方案 – Aravind

回答

0

基本上你想使用的$_GET變量沒有設置。 爲了確保應用程序傳遞正確的變量,請使用var_dump($_GET);來查看它傳遞的變量。

有關的錯誤的詳細信息,請參閱:php notice undefined variable and notice undefined index

+0

要麼解釋答案,要麼不發佈解決方案,發表評論。 – sagi