Jump to content

updating problem..


corillo181

Recommended Posts

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

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.