Reputation: 1357
I have this php file for store the logout time. Using insert query I store the login time first. Then I store the logout time using this logout script. The error I'm getting is the one I mentioned in my code which is failed to insert logout time
. the $lgotime
and $lrec
are echoing correctly. Below is my code:
<?php
session_start();
$lgotime = date("Y-m-d H:i:s");
$lrec = $_SESSION['lreclast'];
echo $lgotime;
echo "</br>";
echo $lrec;
mysql_query("UPDATE tbl_login_record SET logoff_time='$lgotime' WHERE id = '$lrec'") or die("failed to insert logout time");
session_destroy();
header("Location:../login.php");
?>
the $lrec
variable is coming from mysql_insert_id()
from the script that has the insert query. Help will be really appreciated.
Upvotes: 1
Views: 3660
Reputation: 587
if your mysql query dosent work you can change your code like this:
mysql_query("UPDATE tbl_login_record SET logoff_time='".$lgotime."' WHERE id = '".$lrec."'") or die("failed to insert logout time");
it always works for me!
Upvotes: 3
Reputation: 8334
Just remove single quotes from the id in your query because it is integer not String
mysql_query("UPDATE tbl_login_record SET logoff_time='$lgotime' WHERE id = $lrec") or die("failed to insert logout time");
Upvotes: 1
Reputation: 116
Change the query into the below format and try,
mysql_query("UPDATE tbl_login_record SET logoff_time='".$lgotime."' WHERE id = '".$lrec."'") or die("failed to insert logout time");
Upvotes: 1
Reputation: 3682
Please give it a try.
You are not using session_start()
on top of this page and change query as
<?php
session_start();
$lgotime = date("Y-m-d H:i:s");
$lrec = $_SESSION['lreclast'];
echo $lgotime;
echo "</br>";
echo $lrec;
mysql_query("UPDATE tbl_login_record SET logoff_time='".$lgotime."' WHERE id = '".$lrec."'") or die("failed to insert logout time");
session_destroy();
header("Location:../login.php");
Upvotes: 1
Reputation: 2012
The problem is that your query is not sending the data, its sending strings
mysql_query("UPDATE tbl_login_record SET logoff_time='$lgotime' WHERE id = '$lrec'") or die("failed to insert logout time");
Should be,
mysql_query("UPDATE tbl_login_record SET logoff_time='{$lgotime}' WHERE id = {$lrec}") or die("failed to insert logout time");
To be honest I would not suggest this either and would use parametrized queries instead.
Upvotes: 1