2011-06-13 38 views
0

这是我的.java机器人不能在mysql数据库

 
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代码)注册的空列和状态列(它们包含值的初始值然后)变为空值(没有值)。我在这里丢失了什么?

+0

什么是'mysql_query'返回?如果它返回false,那么'mysql_error'告诉你什么? (顺便说一句,你的文章中的引号有点奇怪 - 尽管可能是剪切/粘贴问题)。 – Mat 2011-06-13 11:50:36

+0

检查HTTP客户端的“连线”输出。它至少会告诉你是否提交了这些值。除此之外,除了在SQL上缺少绑定之外,所有表面都看起来不错。 – 2011-06-13 11:55:39

+0

我没有太多的经验,但我不认为在查询中有引号。也许仔细检查一下。这不是一个正确的字符串连接。 – DArkO 2011-06-13 11:56:52

回答

0

尝试回声/日志的字符串,你投入的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中运行它。