这是我表单中的部分代码:
<br><input type="checkbox" checked="yes" name="country[]" value="1" />Asia/Pacific Region
<br><input type="checkbox" checked="yes" name="country[]" value="2" />Europe
<br><input type="checkbox" checked="yes" name="country[]" value="3" />Andorra
...
<br><input type="checkbox" checked="yes" name="country[]" value="250" />Jersey
<br><input type="checkbox" checked="yes" name="country[]" value="251" />Saint Barthelemy
<br><input type="checkbox" checked="yes" name="country[]" value="252" />Saint Martin
这是我的 PHP 代码:
$country=$_POST['country'];
...
foreach ($country as $country) {
$sql="INSERT INTO sites_countries (siteID, country) VALUES ('$id', '$country')";
# execute SQL command
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
但是我查看了我的数据库,它似乎只到 127,那么 $country 总是 127
最佳答案
如果字段“country”定义为带符号的 tinyint,则最大值为 127。
见http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
编辑:即使您的 MySQL 服务器允许您插入超出范围的数据,您也可以获得有关截断的信息,例如与
SHOW WARNINGS
这将导致类似 "Level";"Code";"Message" "Warning";"1264";"Out of range value for column 'i' at row 1"的结果 您还可以将服务器置于严格模式,并在任何数据超出范围时收到错误消息。
见http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
关于mysql - PHP值不会超过127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/901315/