我正在尝试使用 android emulator 3.1 插入 mysql,但我的问题我无法插入,它在 logcat 中给了我错误,有人可以帮我请在这里我的代码。有趣的部分是将空数据插入我的 mysql。
PHP
mysql_select_db("properties", $con);
$sql="INSERT INTO customer(C_Name, C_Surname, C_ID, C_Address, C_Email, C_CellNumber, C_UserName, C_Password)
VALUES('$_POST[C_Name]','$_POST[C_Surname]','$_POST[C_ID]','$_POST[C_Address]','$_POST[C_Email]',
'$_POST[C_CellNumber]','$_POST[C_UserName]','$_POST[C_Password]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
//echo "1 record added";
echo json_encode($sql);
mysql_close($con);
还有我的活动
protected String doInBackground(String... args) {
String name = input_Name.getText().toString();
String surname = input_Surname.getText().toString();
String ID = input_ID.getText().toString();
String Address = input_Address.getText().toString();
String Emial = input_Email.getText().toString();
String CellNumber = input_CellNumber.getText().toString();
String Username = input_UserName.getText().toString();
String Pasword = input_Password.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name",name));
params.add(new BasicNameValuePair("surname",surname));
params.add(new BasicNameValuePair("ID",ID));
params.add(new BasicNameValuePair("Address",Address));
params.add(new BasicNameValuePair("Emial",Emial));
params.add(new BasicNameValuePair("CellNumber",CellNumber));
params.add(new BasicNameValuePair("Username",Username));
params.add(new BasicNameValuePair("Pasword",Pasword));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Toast.makeText(RegisterUsers.this,"Customer has been Registered",Toast.LENGTH_LONG).show();
// closing this screen
// finish();
} else {
// failed to create product
Toast.makeText(RegisterUsers.this,"Error",Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
}
我试图用谷歌搜索错误但没有找到它。我只需要知道该怎么做,因为它尝试了这个代码将近 3 个小时。我的日志猫错误
LOGCAT
06-18 22:46:45.045: E/JSON Parser(1453): Error parsing data org.json.JSONException: Value INSERT INTO customer(C_Name, C_Surname, C_ID, C_Address, C_Email, C_CellNumber, C_UserName, C_Password)
06-18 22:46:45.045: E/JSON Parser(1453): VALUES('','','','','',
06-18 22:46:45.045: E/JSON Parser(1453): '','','') of type java.lang.String cannot be converted to JSONObject
06-18 22:46:45.065: W/dalvikvm(1453): threadid=9: thread exiting with uncaught exception (group=0x40014760)
06-18 22:46:45.095: E/AndroidRuntime(1453): FATAL EXCEPTION: AsyncTask #1
06-18 22:46:45.095: E/AndroidRuntime(1453): java.lang.RuntimeException: An error occured while executing doInBackground()
06-18 22:46:45.095: E/AndroidRuntime(1453): at android.os.AsyncTask$3.done(AsyncTask.java:266)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.lang.Thread.run(Thread.java:1020)
06-18 22:46:45.095: E/AndroidRuntime(1453): Caused by: java.lang.NullPointerException
06-18 22:46:45.095: E/AndroidRuntime(1453): at de.vogella.android.locationapi.simple.RegisterUsers$CreateNewCustomer.doInBackground(RegisterUsers.java:136)
06-18 22:46:45.095: E/AndroidRuntime(1453): at de.vogella.android.locationapi.simple.RegisterUsers$CreateNewCustomer.doInBackground(RegisterUsers.java:1)
06-18 22:46:45.095: E/AndroidRuntime(1453): at android.os.AsyncTask$2.call(AsyncTask.java:252)
06-18 22:46:45.095: E/AndroidRuntime(1453): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-18 22:46:45.095: E/AndroidRuntime(1453): ... 4 more