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
https://forums.phpfreaks.com/topic/14054-timestamp-problem/
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
https://forums.phpfreaks.com/topic/14054-timestamp-problem/#findComment-54939
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
https://forums.phpfreaks.com/topic/14054-timestamp-problem/#findComment-54942
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.