Jump to content

Qusetion?


Trium918

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

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

Archived

This topic is now archived and is closed to further replies.

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