Android无法更新mysql数据库中的表

标签 android mysql database

这是我的.java

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(“http://*******.com/mobileproject/updateclass.php”);
try {
List nameValuePairsUpdate = new ArrayList(2);
nameValuePairsUpdate.add(new BasicNameValuePair(“code”, aCode[i]));
nameValuePairsUpdate.add(new BasicNameValuePair(“section”, aSection[i]));
nameValuePairsUpdate.add(new BasicNameValuePair(“registered”, Integer.toString(registered)));
nameValuePairsUpdate.add(new BasicNameValuePair(“empty”, Integer.toString(empty)));
nameValuePairsUpdate.add(new BasicNameValuePair(“status”, status));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
} catch (IOException e) {
}

这是我的 .php

mysql_connect(“localhost”,”******”,”********”);
mysql_select_db(“*******”);
$registered = $_POST['registered'];
$empty = $_POST['empty'];
$status = $_POST['status'];
$code = $_POST['code'];
$section = $_POST['section'];
mysql_query(“UPDATE Class SET registered = ‘$registered’ , empty = ‘$empty’ , status = ‘$status’ WHERE code = ‘$code’ AND section = ‘$section’”);

我的问题是,当我单击按钮(.java 中的代码)时,注册列、空列和状态列(最初它们包含值,然后)变为空(无值)。我在这里缺少什么?

最佳答案

尝试回显/记录您放入 mysql_query 的字符串,例如:

$sql = “UPDATE Class SET registered = ‘$registered’ , empty = ‘$empty’ , status = ‘$status’ WHERE code = ‘$code’ AND section = ‘$section’”;
echo $sql; // or yourowndebuglogfunction($sql);
mysql_query($sql);

然后尝试直接在mysql中运行。

关于Android无法更新mysql数据库中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6329975/

相关文章:

mySQL - 显示带有 LEFT JOIN 表的数据,但不显示连接数据的结果

android - 是否可以在没有root权限的情况下读取已单独复制到Android sd卡的数据?

java - 从PlaylistID Youtube获得视频ID?

android - fatal error : iostream: No such file or directory

mysql - SQL表将日期列转换为纪元

mysql - 增强的 SQL 替换功能 - 能够处理可变部分

java - 在 ListView 中显示数据库

php - 在 php/mysql 表中使用多重连接作为对象或类似的东西

php - 选择似乎不起作用

c# - 桌面应用程序可能的数据访问层设计模式是什么?