值未正确输入到MySQL数据库中 [英] Value not being entered into the MySQL database correctly

查看:85
本文介绍了值未正确输入到MySQL数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未正确将字段(电话号码)的值输入数据库.也就是说,输入后该值似乎会发生变化.

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.

电话号码的最大长度为11个字符.在HTML表单中,我将4个初始默认字符设置为1876-牙买加的区号.

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>

然后,在php端:

$phone = $_POST['phone'];

该字段中的所有其他值均已正确输入.

All other values in the field are being entered correctly.

我哪里出错了?

更新:

在MySQL表中,列数据类型为int.

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')";

例如,我尝试输入3025009,它存储的是2147483647之类的随机值.

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

推荐答案

这是数据类型为int的问题,如果您尝试存储更大的值然后限制,则它可以在其中存储最大2147483647的值,那么它将存储数据类型的最大值限制为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

这篇关于值未正确输入到MySQL数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆