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. :oops: 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

&lt;?php
&lt;?php
$time_now = time();
$time_later = (time()+3600);
?&gt;
&lt;?php

$query = "select user_id from sessions where SID = '$SID' and user_type ='$user_type' and time_expire &gt; $time_now";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error() );
		
		$numrows =mysql_num_rows($result);
		if($numrows &gt;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.'&lt;br&gt;'.mysql_error());
		}
else
{ 
echo "&lt;meta http-equiv=refresh content='1;url=http://www.vvds/support/admin/alogin.php'&gt;";
exit;
}
?&gt;
?&gt;