Page 1 of 1
Working with time
Posted: Wed Nov 13, 2002 8:46 pm
by lloydie-t
I'm not that brilliant at MySQL, but i cannot work out why this string is causing an error. What I want to do is display user ID if the time is less than the time in a record.
Code: Select all
select user_id from sessions where SID = '65c55d073740a7b4b43e6f28d72922da' and time_expire<time()
Posted: Thu Nov 14, 2002 2:04 am
by twigletmac
What is the error you are getting?
Mac
Posted: Thu Nov 14, 2002 9:20 am
by cctrax
It would make our job a little easier if you posted the error

Posted: Thu Nov 14, 2002 10:08 am
by lloydie-t
How Dim am I. It turns out that the time I was using is Unix Time as set by PHP and not MySQL.

I am more or less sorted now except I think my code looks a bit sloppy because I do not know how to process the PHP time in an SQL query. Have a look, see what you think.
Code: Select all
<?php
<?php
$time_now = time();
$time_later = (time()+3600);
?>
<?php
$query = "select user_id from sessions where SID = '$SID' and user_type ='$user_type' and time_expire > $time_now";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error() );
$numrows =mysql_num_rows($result);
if($numrows >0)
{
$sql ="UPDATE sessions SET time_expire = '$time_later' WHERE SID = '$SID' ";
mysql_query($sql) or die('An error occured executing sql statement. SQL='.$sql.'<br>'.mysql_error());
}
else
{
echo "<meta http-equiv=refresh content='1;url=http://www.vvds/support/admin/alogin.php'>";
exit;
}
?>
?>