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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.