/    Sign up×
Community /Pin to ProfileBookmark

mysql php help.

Hello.

i have this code bellow wich inserts a users ip adress into my database but i have a problem. the code right now works, but when it inserts the ip adress is just get’s the first numbers… like if it is for example 127.0.0.1 it only takes 127 into the database and not the rest, why is this?

[code=php]
<?php
include(‘other/config.php’);

mysql_connect($host, $dbname, $dbpass) or die(mysql_error());
mysql_select_db($dbuser) or die(mysql_error());

$ip_address = $_SERVER[‘REMOTE_ADDR’];

$process = mysql_query(“INSERT INTO `stats` (`ip`, `views`) VALUES (‘”.mysql_real_escape_string($ip_address).”‘, 1) ON DUPLICATE KEY UPDATE `views` = `views` + 1″) or die(mysql_error());

?> [/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 06.2007 — What is the column type/size definition for the "ip" column?
Copy linkTweet thisAlerts:
@holidayDec 06.2007 — NogDog is right! You should have the ip column type as VARCHAR and length as 11
Copy linkTweet thisAlerts:
@NogDogDec 06.2007 — NogDog is right! You should have the ip column type as VARCHAR and length as 11[/QUOTE]
Length of 15 would be better (e.g.: '123.123.123.123').
Copy linkTweet thisAlerts:
@holidayDec 06.2007 — thanks you NogDog... For some reason I had in my head that an ip was formatted like 000.000.000 that's weird
×

Success!

Help @evania spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 7.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @Nanditha,
tipped: article
amount: 1000 SATS,
)...