views:

170

answers:

3

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

+6  A: 

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

VolkerK
well how can i change it?
Hintswen
After you have checked that it is in fact a tinyint with SHOW CREATE TABLE tblName and that the changes will not break any other code using this table you can alter the table definition, see http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
VolkerK
@MasterPeter - tried that, still maxes at 127
Hintswen
BAHAHAHA it was signed...
Hintswen
I was reading that tinyint is 0-255 so i used it, but didn't change it to unsigned.
Hintswen
so it's really a mysql issue? retag the question if i'm right.
Peter Perháč
+3  A: 

Please check your country data column type. If this column is tinyint, check if it is "unsigned".

Signed tinyint are constrainted to -127/127

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

PulsarBlow
+3  A: 

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.

PatrikAkerstrand