简体   繁体   中英

Value not being entered into the MySQL database correctly

The value for a field (phone number) isn't being correctly entered into the database. That is, the value seems to change once it's entered.

The phone number has a max limit of 11 characters. In the HTML form, I set the 4 initial defaults characters to 1876 - Jamaica's area code.

<tr>
                <td>Phone:</td>
                <td><input type="text" name="phone" maxlength="11" value="1876" onkeypress="return isNumberKey(event)"/></td>
              </tr>

Then, on the php side:

$phone = $_POST['phone'];

All other values in the field are being entered correctly.

Where did I go wrong?

UPDATE:

In the MySQL table, the column data type is an int.

It's inserted using this query:

$query = "INSERT INTO users (id, first_name, last_name, date_of_birth, email, phone) 
      VALUES ('$id','$first_name','$last_name','$encrypted_dob','$email','$phone')";

For example, I tried entering, say, 3025009 and it's storing some random value like 2147483647.

It is a problem of datatype signed int which is able to store maximum 2147483647 value in it if you try to store larger value then limit then it will store datatype's maximum limit which is 2147483647. so please use appropriate datatype to store integer value. some references are follows which may fulfill your requirement.

datatype                    largest value

bigint unsigned             18446744073709551615
bigint signed               9223372036854775807
int unsigned                4294967295

它的整数大小的问题,您必须将数据类型大小“ int”更改为“ bigint”,然后才能获取正确的值,尝试这样做

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM