android设备上的代码是:
public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
is.close();
json = sb.toString();
Log.e("JSON", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
PHP服务器上的代码是:
$name = $_POST['name'];
$email= $_POST['email'];
$password = $_POST['password'];
$user = $db->storeUser($name, $email, $password);
if($user){
echo json_encode($response). "User Stored Successfully";
}
else{
echo json_encode($response). "Error Occured in Registration";
}
其中 storeUser 是:
public function storeUser($name, $email, $password) {
$result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email','$encrypted_password', '$salt', NOW())");
}
该过程有效,将消息发送回android设备,但详细信息未插入MySQL数据库?
我想要的只是从安卓设备发布详细信息并将它们插入到我服务器上的 MySQL 数据库中。
任何人都知道为什么会这样,我做错了什么?