adam291086 Posted January 16, 2008 Share Posted January 16, 2008 if revraz is correct then use update. To keep thing simple you can always use update. When i a new user signs up add in the insert last loged in then. Because theoretically that have sign up and therefore logged in. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441017 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 I tried that revraz and got a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441018 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Echo the query so we can check it for errors before you run mysql_query on it. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441021 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 How do I do that (i'm just starting out!). Do I use: echo $_SESSION['SESS_MEMBER_ID']); Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441024 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 you have somehting like $query = "select * FROM adam"; $adam = mysql_query($query); we need you to echo $query and show us the result Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441026 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 Aaaah - I get it. The result is" SELECT member_id FROM members WHERE login='james_payne' AND passwd='3de0746a7d2762a87add40dac2bc95a0' If I echo the session id I get the correct member_id as well. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441028 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 echo the update query. Thats where the problem is . Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441029 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Wrong one, we want the update query. $query="UPDATE members SET last_visits = (NOW()) WHERE member_id ='".$_SESSION['SESS_MEMBER_ID'])"' "; echo $query; exit; $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441030 Share on other sites More sharing options...
tapos Posted January 16, 2008 Share Posted January 16, 2008 Please have a check with the following code <?php //Start session session_start(); include('../includes/config.php'); include('../includes/opendb.php'); //Sanitize the value received from login field //to prevent SQL Injection if(!get_magic_quotes_gpc()) { $login=mysql_real_escape_string($_POST['login']); }else { $login=$_POST['login']; } //Create query $query="SELECT member_id FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($query); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result)>0) { //Login Successful session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID']=$member['member_id']; session_write_close(); $query="update members set last_visit = NOW() WHERE member_id ='$member[member_id]'"; $result=mysql_query($query); header("location: /admin.php"); exit(); } else { //Login failed header("location: login_failed.php"); exit(); } }else { die("Query failed"); } ?> -- Thanks, Tapos Pal http://tapos.wordpress.com Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441035 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 Wrong one, we want the update query. $query="UPDATE members SET last_visits = (NOW()) WHERE member_id ='".$_SESSION['SESS_MEMBER_ID'])"' "; echo $query; exit; $result = mysql_query($query); Get a blank page again. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441037 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 If your fieldname is last_visit then I made a typo and used last_visits Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441039 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 Please have a check with the following code <?php //Start session session_start(); include('../includes/config.php'); include('../includes/opendb.php'); //Sanitize the value received from login field //to prevent SQL Injection if(!get_magic_quotes_gpc()) { $login=mysql_real_escape_string($_POST['login']); }else { $login=$_POST['login']; } //Create query $query="SELECT member_id FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($query); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result)>0) { //Login Successful session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID']=$member['member_id']; session_write_close(); $query="update members set last_visit = NOW() WHERE member_id ='$member[member_id]'"; $result=mysql_query($query); header("location: /admin.php"); exit(); } else { //Login failed header("location: login_failed.php"); exit(); } }else { die("Query failed"); } ?> -- Thanks, Tapos Pal http://tapos.wordpress.com HOORAY - It works!!!! Thanks Tapos Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441040 Share on other sites More sharing options...
tapos Posted January 16, 2008 Share Posted January 16, 2008 It's my pleasure. U should make the post solved. -- Thanks, Tapos Pal http://tapos.wordpress.com Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441043 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks for all your help guys. I understand I need to use the UPDATE query instead of INSERT, but why did: WHERE member_id ='$member[member_id]'"; work instead of: WHERE member_id ='".$_SESSION['SESS_MEMBER_ID'])"' "; Does this mean the session is not being set correctly? Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441047 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 No, my parenthesis were off. The session would work fine I'm sure. $query="UPDATE members SET last_visit = NOW() WHERE member_id ='".$_SESSION['SESS_MEMBER_ID']"' "; Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441051 Share on other sites More sharing options...
adam291086 Posted January 16, 2008 Share Posted January 16, 2008 i think its because you are treating the session like a string with the " " around it. To see if the session is set just echo it out echo $_SESSION['SESS_MEMBER_ID'] Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441053 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 You probably have error reporting turned off in your php.ini, so if you check your Log file, you would have received a syntax error instead of a blank screen. Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441057 Share on other sites More sharing options...
giraffemedia Posted January 16, 2008 Author Share Posted January 16, 2008 i think its because you are treating the session like a string with the " " around it. To see if the session is set just echo it out echo $_SESSION['SESS_MEMBER_ID'] I did try it without the " " but got a blank page. echo $_SESSION['SESS_MEMBER_ID']; That works fine and the session is being set. I guess I need to learn more about debugging. I'm ordering the VTC training cd on php so hopefully i'll be able to learn a lot more soon. Thanks for all you help. James Quote Link to comment https://forums.phpfreaks.com/topic/86285-solved-user-login-timestamp-or-datetime/page/2/#findComment-441058 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.