Matt
Matt

Reputation: 1

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. The column is an unsigned int(10) in MYSQL 5.5.

Error: Data truncated for column 'initial_ip' at row 1

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

Upvotes: 0

Views: 600

Answers (3)

tsbelanger
tsbelanger

Reputation: 1

Your IP column in your database needs to be of type VARCHAR.

Upvotes: 0

mkk
mkk

Reputation: 7693

You are trying to store something like:

  127.0.0.1

as an integer.. this looks obviously wrong? Change int(10) into varchar(15) and it should work.

Upvotes: 0

Thorsten
Thorsten

Reputation: 5644

You have to convert the IP to an integer, or save it as string.

BTW: What is that space for that you add to the IP?

Upvotes: 6

Related Questions