我一直很困惑地想到我的代码出了什么问题。 当我尝试为特定列插入新值时,MySQL会继续写入并将其保存到具有相同值的表中。
这是我的表格结构(预订表):
reservation
-----------------
id_reservation int(3)
no_seat1 varchar(4)
no_seat2 varchar(4)
no_account int(13)
这是我的预订.java代码:
reservation = (Button) findViewById(R.id.bt_reservation);
reservation.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("no_seat1", no_seat1.getText().toString()));
postParameters.add(new BasicNameValuePair("no_seat2", no_seat2.getText().toString()));
postParameters.add(new BasicNameValuePair("no_account", no_account.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://10.0.2.2/cinemainfo/reservation.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
no_seat1.setText("");
no_seat2.setText("");
no_account.setText("");
Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
}
}
}
});
这是我的PHP代码(reservation.php):
$no_seat1 = $_POST['no_seat1'];
$no_seat2 = $_POST['no_seat2'];
$no_account = $_POST['no_account'];
$db_con = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);
$query = "INSERT INTO reservation VALUES ('','$no_seat1', '$no_seat2', '$no_account')";
$result = mysql_query($query) or die("FAILED save data!");
当我在模拟器中运行时..没关系,但保存在我的预订表中的数据似乎是错误的..对于第一次插入,no_account的数据是2147483647
,我从未输入该数字。 。
所以我尝试了第二次插入,它仍然是相同的...保存在no_account列中的数据是2147483647
..我不知道我的代码有什么问题......
我非常感谢你给我的任何帮助。谢谢你:)。