简体   繁体   English

IP 地址在 MYSQL 中被截断

[英]IP Address Truncated in MYSQL

I'm trying to insert the IP address in mysql, but the error message states that the IP is being truncated.我试图在 mysql 中插入 IP 地址,但错误消息指出 IP 被截断。 The column is an unsigned int(10) in MYSQL 5.5.该列是 MYSQL 5.5 中的无符号 int(10)。

Error: Data truncated for column 'initial_ip' at row 1错误:第 1 行的列“initial_ip”的数据被截断

PHP5 PHP5

//get the IP address
if ( isset($_SERVER["REMOTE_ADDR"]) )    {
    $ip=$_SERVER["REMOTE_ADDR"] . ' ';
    } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    {
    $ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
    } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    {
    $ip=$_SERVER["HTTP_CLIENT_IP"] . ' ';
}

Thanks for any help谢谢你的帮助

You have to convert the IP to an integer , or save it as string.您必须将 IP 转换为 integer ,或将其保存为字符串。

BTW: What is that space for that you add to the IP?顺便说一句:您添加到 IP 的空间是多少?

You are trying to store something like:您正在尝试存储以下内容:

  127.0.0.1

as an integer.. this looks obviously wrong?作为 integer .. 这看起来显然是错误的? Change int(10) into varchar(15) and it should work.将 int(10) 更改为 varchar(15) ,它应该可以工作。

Your IP column in your database needs to be of type VARCHAR.数据库中的 IP 列需要是 VARCHAR 类型。

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

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