Jump to content

Check if the ip is already in the database?


AbydosGater

Recommended Posts

Hi, ive been working on a users online script,

But i was wondering how owuld i go about if checking if the ip address was already in a row in the database? instead of making a new row everytime the user refreshs, how would i check if the users ip is already in the ip column, so that i could insert a new record or just update the old one?

Thanks Abydos
well you have a table...obviously...this table stores the users IPs right and has how many times they have been to the site etc. well i am assuming your table layout is like this:

id (int,11,auto_increment) | ip (varchar,255) | hits (int,11)
1                                    125.15.73.9        14
2                                    125.15.73.2        1

etc etc.

aight... now. on your log file or whatever have this code.
[code=php:0]
$ip = $_SERVER['REMOTE_ADDR'];
if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE `ip`='".$ip."'")) == 0){
//insert a new row etc.
}else{
//update the old row with +1 hits.
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.