首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android无法更新mysql数据库中的表

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

Stack Overflow用户
提问于 2011-06-13 19:46:13
回答 1查看 1.5K关注 0票数 0

这是我的.java

代码语言:javascript
复制
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

代码语言:javascript
复制
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中的代码)时,registered、empty和status列(初始它们包含值,然后)变为空(没有值)。我在这里错过了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-13 19:56:39

尝试回显/记录您放入mysql_query中的字符串,如下所示:

代码语言:javascript
复制
$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中运行它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6329975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档