错误我的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);
?>
请建议我如何解决问题?。
答案 0 :(得分:0)
基本上,您要使用的$_GET
变量未设置。
为了确保应用程序传递正确的变量,请使用var_dump($_GET);
查看它传递的变量。
有关错误的详细信息,请参阅:php notice undefined variable and notice undefined index