简体   繁体   English

值未正确输入到MySQL数据库中

[英]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. 电话号码的最大长度为11个字符。 In the HTML form, I set the 4 initial defaults characters to 1876 - Jamaica's area code. 在HTML表单中,我将4个初始默认字符设置为1876-牙买加的区号。

<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: 然后,在php端:

$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. 在MySQL表中,列数据类型为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. 例如,我尝试输入3025009,它存储了一些随机值,例如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. 这是数据类型为int的问题,如果您尝试存储更大的值然后限制,则它可以存储最大2147483647的值,那么它将存储数据类型的最大限制2147483647。因此,请使用适当的数据类型来存储整数值。 some references are follows which may fulfill your requirement. 以下参考可能会满足您的要求。

datatype                    largest value

bigint unsigned             18446744073709551615
bigint signed               9223372036854775807
int unsigned                4294967295

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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