Darkmatter5 Posted July 2, 2008 Share Posted July 2, 2008 Say I have a user logged in on my site where the session's name is the primary key of the member record called member_id. when a member logs in I set a field named logged_in in the members record to 1. When the user wants to log out I want to set the field to 0, if I have the following log out script <?php include 'library/config.inc.php'; require('C:\wamp\www\library\opendb.php'); $pagedb = "members"; session_start(); if(session_is_registered('member_id')) { session_unset(); session_destroy(); mysql_query("UPDATE " .$dbname. "." .$pagedb. " SET logged_in = '0' WHERE member_id = '" .$member_id. "' ") or die(mysql_error()); echo "Logged out!"; // header("Location: index.php"); } else { echo "Not logged in!"; // header("Location: index.php"); } ?> How can I pass the member_id to this page from other pages so I can reference which member_id to set the field to? As I read this it sounds a bit confusing, let me know if this doesn't make sense and I'll elaborate. Quote Link to comment Share on other sites More sharing options...
severndigital Posted July 2, 2008 Share Posted July 2, 2008 if i understand this you have the answer already if(session_is_registered('member_id')) { $member_id = $_SESSION['member_id']; //add this line session_unset(); session_destroy(); mysql_query("UPDATE " .$dbname. "." .$pagedb. " SET logged_in = '0' WHERE member_id = '" .$member_id. "' ") or die(mysql_error()); give that a shot -c Quote Link to comment Share on other sites More sharing options...
Darkmatter5 Posted July 2, 2008 Author Share Posted July 2, 2008 As far as I could tell my code seemed good, but the member_id didn't seem to pass. So here's another idea. I put in more script to see exactly what is being passed into the mysql_query. Here's the code <?php include 'library/config.inc.php'; require('C:\wamp\www\library\opendb.php'); $pagedb = "members"; session_start(); if(session_is_registered('member_id')) { session_unset(); session_destroy(); mysql_query("UPDATE " .$dbname. "." .$pagedb. " SET logged_in = '0' WHERE member_id = '" .$member_id. "' ") or die(mysql_error()); //NEW CODE IS THE FOLLOWING LINE echo "UPDATE " .$dbname. "." .$pagedb. " SET logged_in = '0' WHERE member_id = '" .$member_id. "'"; echo "<br>Logged out!<br> <a href='index.php'>Index</a>"; // header("Location: index.php"); } else { echo "Not logged in!<br> <a href='index.php'>Index</a>"; // header("Location: index.php"); } ?> When it's output it says UPDATE ecabinet.members SET logged_in = '0' WHERE member_id = '' Logged out! Index So as you can see the member_id isn't being passed. See the thing is I have a link on my index.php file that says this: <a href="logout.php">Logout</a> Is there anything I need to add to the link to pass the member_id? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.