AbydosGater Posted November 4, 2006 Share Posted November 4, 2006 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 https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/ Share on other sites More sharing options...
cunoodle2 Posted November 4, 2006 Share Posted November 4, 2006 do a search on the database and see if there are any matches on the IP address. IF there are then don't add a new row. If you need more help let us know the table/field structure and we will go from there. Link to comment https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/#findComment-119754 Share on other sites More sharing options...
AbydosGater Posted November 4, 2006 Author Share Posted November 4, 2006 Yeah but how would i go about searching the database? Link to comment https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/#findComment-119756 Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 Just run a query looking for that IP, just guessing here I'm a newb :($sql = "Select ip_col FROM TABLE WHERE ip='users_ip'";I take it your doing this through a login? Hope I was some helpCheers!Stephen Link to comment https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/#findComment-119787 Share on other sites More sharing options...
JasonLewis Posted November 5, 2006 Share Posted November 5, 2006 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 142 125.15.73.2 1etc 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 https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/#findComment-119791 Share on other sites More sharing options...
AbydosGater Posted November 5, 2006 Author Share Posted November 5, 2006 Perfect, genious, would never of thought of that!Thanks Link to comment https://forums.phpfreaks.com/topic/26182-check-if-the-ip-is-already-in-the-database/#findComment-119919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.