Jump to content

Delete code error


graham23s

Recommended Posts

Hi Guys,

 

i'm trying to delete old entries in the database but i'm getting a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result " when the code is ran.

 

<?php
     $number_of_days = 60;
     // using UNIX timestamp in the table.../////////////////////////////////////////////
      
     $stamp = strtotime("-".$number_of_days." day");  
     
     // using MySQL DATETIME...//////////////////////////////////////////////////////////
     $stamp = date("Y-m-d H:i:s", strtotime("-".$number_of_days." day"));
     
     $result = mysql_query("SELECT * FROM `uploaded_files` WHERE `date_added`  <= ".$stamp);
     while ($row = mysql_fetch_array($result)) {

     $file = $row['file_name'];

     unlink("uploads/$file");

     // remove files...//////////////////////////////////////////////////////////////////
     }
     
     mysql_query("DELETE FROM `uploaded_files` WHERE `date_added ` <= ".$stamp); // remove entries from database. 
?>

 

i can't seem to see the error!

 

thanks for nay help guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/54670-delete-code-error/
Share on other sites

Hi Mate,

 

the connection stuff is above those lines of code i just never showed them:)

 

heres the error i get once run:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '12:30:40' at line 1

 

any ideas on what the proble could be?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/54670-delete-code-error/#findComment-270687
Share on other sites

$result = mysql_query("SELECT * FROM `uploaded_files` WHERE `date_added`  <= ".$stamp) or die(mysql_error());

 

Should tell you your error.

 

First try adding this though.

 

$result = mysql_query("SELECT * FROM `uploaded_files` WHERE `date_added`  <= '$stamp'");

Link to comment
https://forums.phpfreaks.com/topic/54670-delete-code-error/#findComment-270688
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.