having huge problems with a simple delete but seem to be getting nowhere, bascially what i want to do is delete an entry in a sessions table if its older than such a date, yet not have ny script fall over if there are no entries in the sessions table
at the moment i am using this
$too_old = "time() - 50";
$query = "DELETE FROM sessions WHERE created < '$too_old'";
$result = mysql_query($query);
which does nothing yet if i change it to...
$query = "SELECT created from sessions WHERE sessionid = 1";
$result = mysql_query($query);
$answer = mysql_result($result, 0);
echo $answer;
it works no problem, so i know my database is fine, also if i put a clause at the end of my "$result = mysql_query($query);" making it
$result = mysql_query($query) or die("Failed!");
it returns failed, please help me if you can cos i've been stuck on this since monday and am a complete beginner.
Let's say that time()=800, what do you think is in the variable $too_old? (Hint: it isn't 750.) Answer: time() - 50
If you are still confused, try echoing out $too_old and see what is displayed. That output is going into your SELECT statement, and since mysql doesn't understand that syntax, the query fails.
but i still dont understand, what i want to do is check is the time older than the current time - 50 (which is short for the moment just to test) so how do i do this if what i have is not correct.
$query = "DELETE FROM sessions WHERE created < '$too_old'";
$result = mysql_query($query) or die("delete failed");
this is what i am using now and works no problem, when i used $too_old = "time() - 50" i had quotes when there should'nt have been any and the time format was the wrong one, so while the code was correct and did'nt create any errors, it did'nt work ether cos the format in the php and in the table were different. I also found an invaluable page on php.net which gives all the date formats for anybody else who needs them
Bookmarks