【发布时间】:2018-09-10 11:41:06
【问题描述】:
我必须根据电子邮件更新我的数据库。我正在使用 Android Networking 更新我的数据库中的数据,但它只会让我服务器超时。这是我的 PHP:
<?php
if(isset($_POST['update']))
{
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "truck_loader";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$address = $_POST['address'];
$query = "UPDATE `users` SET
`name`='".$name."',`address`='".$address."',`mobile`= $mobile WHERE `email`
= $email";
$result = mysqli_query($connect, $query);
if(mysqli_query($connect,$query))
{
$response['success'] = '1';
$response['message']='Updated successfully';
echo json_encode($response);
exit;
}
else
{
$response['success'] = '0';
$response['message']='Updation failed';
echo json_encode($response);
exit;
}
mysqli_close($connect);
}
?>
这是我在 android 中的代码:
private void updateProfile() {
HashMap<String,String> params=new HashMap<>();
params.put("name",name.getText().toString());
params.put("email",email.getText().toString());
params.put("mobile",mobile.getText().toString());
params.put("address",address.getText().toString());
AndroidNetworking.post("update.php").addBodyParameter(params).setTag("Profile").setPriority(Priority.LOW).build().getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
try {
if(response.getString("success").equals("1")) {
Toast.makeText(FragProfile.this, response.getString("message"), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(FragProfile.this, response.getString("message"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ANError anError) {
Toast.makeText(FragProfile.this, "Server timeout please try again later", Toast.LENGTH_SHORT).show();
}
});
}
没有异常显示代码,所以我对错误可能是什么感到困惑。 编辑:我正在为我的实习项目中的个人资料活动制作这个,因此,我没有在其中使用会话。
【问题讨论】:
标签: php android xampp android-networking