corillo181 Posted February 26, 2007 Share Posted February 26, 2007 this code is working fine when a person is using a computer that uses one single ip.. but if the computer switches from ip to ip every time it keeps inserting a new rows. i know how this happens it's because since is not the same ip it insert a new one. i want to know how can i switch my code so when a new user logs in the row is updated but if the ip of that users changes i want to switch in the same row. if($user_id){ $mysql_user_log=mysql_query("SELECT user_ip FROM users_online WHERE user_ip='$user_ip'")or die(mysql_error()); $user_count=mysql_num_rows($mysql_user_log); if($user_count==0){ $insert_login=mysql_query("INSERT INTO users_online(user_id,user_name,user_ip,href_add,timestamp)VALUES('$user_id','$user_name','$user_ip','$href_add','$timestamp')")or die(mysql_error()); }elseif($user_count==1){ $update_login=mysql_query("UPDATE users_online SET user_id='$user_id', user_name='$username', href_add='$href_add', WHERE user_ip='$user_ip'"); } } Link to comment https://forums.phpfreaks.com/topic/40253-updating-problem/ Share on other sites More sharing options...
shoz Posted February 26, 2007 Share Posted February 26, 2007 If you change the test in both WHERE clauses to the following you should get the desired result. WHERE user_id='$user_id'" If user_id isn't an unchangeable unique identifier for each user then use username instead. Link to comment https://forums.phpfreaks.com/topic/40253-updating-problem/#findComment-194748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.