这是我的代码,我需要插入 mysql 数据库我有 mysql,php,android
1)我遇到的问题,我需要一个成功的结果到我的php,这样我就可以使用android.so插入我的php代码:
2)我正在使用的表有一个外键 : Provinces_idProvinces
。
$result = mysql_query("INSERT INTO property( Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, Provinces_idProvinces)
VALUES('$_POST[Pname]',$_POST[P_Price],'$_POST[P_Desc]','$_POST[P_City]','$_POST[P_Size]','$_POST[P_Rooms]',$_POST[P_garage],'$_POST[P_Address]',$_POST[P_Long],$_POST[P_Lat],$_POST[Provinces_idProvinces])");
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = $result ;
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
echo $response["success"];
// echoing JSON response
echo json_encode($response);
}
还有我传递参数的类,但它给了我一个错误:
List<NameValuePair> params = new ArrayList<NameValuePair>();
Log.d("Parameters","1");
params.add(new BasicNameValuePair("Pname",Pname));
params.add(new BasicNameValuePair("P_Price",Prices));
params.add(new BasicNameValuePair("P_Desc",Desc));
params.add(new BasicNameValuePair("P_City",city));
params.add(new BasicNameValuePair("P_Size",Size));
params.add(new BasicNameValuePair("P_Rooms",bedNumber));
params.add(new BasicNameValuePair("P_garage",Garnums));
params.add(new BasicNameValuePair("P_Address",Address));
params.add(new BasicNameValuePair("P_Long",longertude));
params.add(new BasicNameValuePair("P_Lat",lattitude));
params.add(new BasicNameValuePair("Provinces_idProvinces",Provnums));
Log.d("Json","obj");
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(save_prop,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
由于 php 返回的值 0,我在 JSON 中遇到错误, 我不知道如何解决这个问题
这里是我的 logCat :
06-25 19:36:40.175: E/JSON Parser(2261): Error parsing data org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject
06-25 19:36:40.175: W/dalvikvm(2261): threadid=10: thread exiting with uncaught exception (group=0x40014760)
06-25 19:36:40.236: E/AndroidRuntime(2261): FATAL EXCEPTION: AsyncTask #1
06-25 19:36:40.236: E/AndroidRuntime(2261): java.lang.RuntimeException: An error occured while executing doInBackground()
06-25 19:36:40.236: E/AndroidRuntime(2261): at android.os.AsyncTask$3.done(AsyncTask.java:266)