Trium918 Posted June 4, 2007 Share Posted June 4, 2007 What would cause this script not to update? I asked because during registeration the last visit date is showing up as 11/30/1999. Also, after I log out then log back in todays last last visit is displayed as 6/04/07. Which is what I aspect, but if I log in at this time tomorrow the last visit is still 6/04/07 instead of 06/05/07. Note: I have to log out and then log back in in order for the script to update. <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $sql="UPDATE members_info SET last_visit=NOW() WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/ Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('n/d/Y', time()); // change to whatever format is stored in the DB $sql="UPDATE members_info SET last_visit=" . $new_last . " WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> Try not using the NOW() function and using php to create the time stamp. Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267712 Share on other sites More sharing options...
Trium918 Posted June 4, 2007 Author Share Posted June 4, 2007 <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('n/d/Y', time()); // change to whatever format is stored in the DB $sql="UPDATE members_info SET last_visit=" . $new_last . " WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> Try not using the NOW() function and using php to create the time stamp. Registeration date = 11/30/99 Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267718 Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; echo 'last received from db is ' . $last . '<br />'; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('n/d/Y', time()); // change to whatever format is stored in the DB echo $new_last . ' is the new last date.'; $sql="UPDATE members_info SET last_visit=" . $new_last . " WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> Try that with those debugging lines and report back the results... Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267723 Share on other sites More sharing options...
Trium918 Posted June 4, 2007 Author Share Posted June 4, 2007 <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; echo 'last received from db is ' . $last . '<br />'; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('n/d/Y', time()); // change to whatever format is stored in the DB echo $new_last . ' is the new last date.'; $sql="UPDATE members_info SET last_visit=" . $new_last . " WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> Try that with those debugging lines and report back the results... Results: last received from db is 2000-00-07 00:00:00 6/04/2007 is the new last date. Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267730 Share on other sites More sharing options...
Trium918 Posted June 4, 2007 Author Share Posted June 4, 2007 Results for frost110: last received from db is 2000-00-07 00:00:00 6/04/2007 is the new last date. I have two different login scripts attached to this post. login1 has some redundant code written with in the script. For instance, runnning two separate queries against the same table? But it is doing what I would like for the script to do! login2 require the user to log in twice before it updates the last visit. Why? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267794 Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 ?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; echo 'last received from db is ' . $last . '<br />'; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('Y-n-d h:i:s', time()); // change to whatever format is stored in the DB echo $new_last . ' is the new last date.'; $sql="UPDATE members_info SET last_visit=" . $new_last . " WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> I modified this part: $new_last = date('Y-n-d h:i:s', time()); // change to whatever format is stored in the DB To reflect the style that the db takes in, note the n-d may need to be d-n, I am not sure. Try that out see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267805 Share on other sites More sharing options...
Trium918 Posted June 4, 2007 Author Share Posted June 4, 2007 Result for frost110 last received from db is 2007-06-04 15:21:12 2007-6-04 04:01:13 is the new last date.You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '04:01:13 WHERE members_id='1'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267836 Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"); if (mysql_num_rows($result)>0){ $row=mysql_fetch_assoc($result); $last=$row['last_visit']; echo 'last received from db is ' . $last . '<br />'; $_SESSION['membersid'] = $row['members_id']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $new_last = date('Y-n-d h:i:s', time()); // change to whatever format is stored in the DB echo $new_last . ' is the new last date.'; $sql="UPDATE members_info SET last_visit='" . $new_last . "' WHERE members_id='{$_SESSION['membersid']}'"; //now only update it mysql_query($sql) or die(mysql_error()); return true; } else return false; } ?> $sql="UPDATE members_info SET last_visit='" . $new_last . "' WHERE members_id='{$_SESSION['membersid']}'"; //now only update it changed the last_visit=' to have single quotes around the variable. Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267878 Share on other sites More sharing options...
Trium918 Posted June 5, 2007 Author Share Posted June 5, 2007 The script isn't updating still. Quote Link to comment https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-268665 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.