PHP value won't exceed 127
Question
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:
$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
Solution
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
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
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
OTHER TIPS
Please check your country data column type. If this column is tinyint, check if it is "unsigned".
Signed tinyint are constrainted to -127/127
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.
Execute the following statement:
SHOW CREATE TABLE sites_countries;
Post the results here.