Working with time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Working with time

Post 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()
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What is the error you are getting?

Mac
cctrax
Forum Commoner
Posts: 36
Joined: Thu Jul 11, 2002 9:05 pm
Location: United States
Contact:

Post by cctrax »

It would make our job a little easier if you posted the error ;)
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post 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;
Post Reply