2011-06-13 56 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中運行它。