Here's part of the code on my form:
这是我表单上代码的一部分:
<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
and this is my php code:
这是我的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());
}
}
but I looked at my database and it seems to only get to 127, then $country is always 127
但我查看了我的数据库,似乎只有127,然后$ country总是127
3 个解决方案
#1
If the field "country" is defined as a signed tinyint the maximum value is 127.
see http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
如果字段“country”被定义为signed tinyint,则最大值为127.请参阅http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
edit: even if your MySQL server allows you to insert data that is out-of-range you can get information about the truncation, e.g. with
编辑:即使您的MySQL服务器允许您插入超出范围的数据,您也可以获得有关截断的信息,例如:同
SHOW WARNINGS
which would result in something like
"Level";"Code";"Message" "Warning";"1264";"Out of range value for column 'i' at row 1"You can also put the server in strict mode and get an error if any data is out-of-range.
see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
#2
Please check your country data column type. If this column is tinyint, check if it is "unsigned".
请检查您的国家/地区数据列类型。如果此列是tinyint,请检查它是否为“unsigned”。
Signed tinyint are constrainted to -127/127
签名的tinyint约束为-127/127
#3
We would need to see your SQL DDL-statements to be able to solve this one. The most probable cause is that you have a data type with too small a range in your database to be able to handle numbers larger than 127.
我们需要看到你的SQL DDL语句能够解决这个问题。最可能的原因是数据库中的数据类型太小,无法处理大于127的数字。
Execute the following statement:
执行以下语句:
SHOW CREATE TABLE sites_countries;
Post the results here.
在此处发布结果。
#1
If the field "country" is defined as a signed tinyint the maximum value is 127.
see http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
如果字段“country”被定义为signed tinyint,则最大值为127.请参阅http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
edit: even if your MySQL server allows you to insert data that is out-of-range you can get information about the truncation, e.g. with
编辑:即使您的MySQL服务器允许您插入超出范围的数据,您也可以获得有关截断的信息,例如:同
SHOW WARNINGS
which would result in something like
"Level";"Code";"Message" "Warning";"1264";"Out of range value for column 'i' at row 1"You can also put the server in strict mode and get an error if any data is out-of-range.
see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
#2
Please check your country data column type. If this column is tinyint, check if it is "unsigned".
请检查您的国家/地区数据列类型。如果此列是tinyint,请检查它是否为“unsigned”。
Signed tinyint are constrainted to -127/127
签名的tinyint约束为-127/127
#3
We would need to see your SQL DDL-statements to be able to solve this one. The most probable cause is that you have a data type with too small a range in your database to be able to handle numbers larger than 127.
我们需要看到你的SQL DDL语句能够解决这个问题。最可能的原因是数据库中的数据类型太小,无法处理大于127的数字。
Execute the following statement:
执行以下语句:
SHOW CREATE TABLE sites_countries;
Post the results here.
在此处发布结果。