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

时间:2011-06-13 11:46:13

标签: 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中的代码)时,已注册的,空的和状态列(初始它们包含值然后)变为空(无值)。我在这里错过了什么?

1 个答案:

答案 0 :(得分:1)

尝试回显/记录你输入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中运行它。