0

how can i update to database status = 1 where id =$id using an update statement after a login for example or a separate page please any one how the string would look like?

this is for a member status script im trying to make it so online members can have there own page

this is just the viewing part and the updating part next

 mysql_select_db("messages") or die(mysql_error()); 
 $data = mysql_query("SELECT on_status FROM users WHERE id='$user_id'") 
 or die(mysql_error()); 
 echo "<table border cellpadding=3 bgcolor=\"00FF00\">"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 echo "<tr>"; 
 echo "<th>User:</th> <td>".$info['user_name'] . "</td> "; 
 echo "<th>Status:</th> <td>".$info['on_status'] . " </td></tr>"; 
 } 
 echo "</table>"; 

?>
<p><br>

<a href="/home.php">Go Back</a><p>
Jay Mee
  • 55
  • 1
  • 11
  • possible duplicate http://stackoverflow.com/questions/1084099/how-to-track-the-online-status-of-users-of-my-website – NullPoiиteя Oct 18 '12 at 16:58
  • I see a problem in your code in the first place. You have id='$user_id instead of id=$user_id or id='$user_id'. Also, if you do WHERE id='$user_id' then you will find, based on the understanding what 'id' usually means, one user only, so your table will always contain one row. Is this is what you are planning to do? – Grzegorz Oct 18 '12 at 17:00

2 Answers2

0

Add a field called status in users table. where users table containing all data of user.

UPDATE status to online when user login.. this code will be placed after validating the username and password..

// Eg: When you starting a session for the user write this update

When a user trying to logout UPDATE status to offline .. this code will be placed beside the session_destroy() statement

NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
0

Try this update statement:

"UPDATE `users` SET `on_status` = 1 WHERE `id` = '$user_id'";

Though, if I may suggest this: Keep a timestamp of the last activity. That way, if the page hasn't been refreshed for more than 5 minutes (or longer), you can display the user as 'offline', even if the user hasn't hit the Logout button.

ATaylor
  • 2,598
  • 2
  • 17
  • 25