Jump to content

Timestamp problem?


dark dude

Recommended Posts

This isnt working:
[quote]
<?

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";
?>[/quote]


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 ^_^
Link to comment
Share on other sites

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.

[code]
$2days = '(TIMESTAMP(NOW()) - 172800)';
[/code]

Instead of:
[code]
$2days = TIMESTAMP(NOW()) - 172800;
[/code]

Also, why not put
[code]
echo ( mysql_error() );
[/code]

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

Cheers.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.