Jump to content

Recommended Posts

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;

}
?>

?>

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267712
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267718
Share on other sites

<?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...

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267723
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267730
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267794
Share on other sites

?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.

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267805
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267836
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/54149-qusetion/#findComment-267878
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.