Jump to content


Photo

Timestamp problem?


  • Please log in to reply
2 replies to this topic

#1 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 08 July 2006 - 09:37 PM

This isnt working:

<?

include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$2days = TIMESTAMP(NOW()) - 172800;

$query="DELETE FROM Messages WHERE DateSent<'$2days'";
mysql_query($query);

echo "Messages Updated";
?>



I want it to delete all files older than 2 days from the database when the script activates, but it doesnt work full stop (Blank screen comes up).

Help much appreciated ^_^

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 08 July 2006 - 09:52 PM

I think the problem is that there is no such function as TIMESTAMP or NOW, if you want it to be included in the
SQL query as text then you will need to enclose it in quotes.

$2days = '(TIMESTAMP(NOW()) - 172800)'; 

Instead of:
$2days = TIMESTAMP(NOW()) - 172800; 

Also, why not put
echo ( mysql_error() );

And it should output the problem if it is with your SQL.

Cheers.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 08 July 2006 - 09:53 PM

You're not seeing your PHP errors because this line is not right (no quotes):
$2days = TIMESTAMP(NOW()) - 172800;

Try this:

$query = 'DELETE FROM Messages WHERE UNIX_TIMESTAMP(DateSent) < UNIX_TIMESTAMP(NOW()) - 172800';
mysql_query($query);

FYI:
While testing/debugging, make sure you have error_reporting(E_ALL); at the top of your script so you can see all of PHP's errors/warnings/notices. Also, I assume you have display_errors on in the php.ini file. Otherwise, set it using ini_set('display_errors', '1'); at the top of your script too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users