graham23s Posted June 7, 2007 Share Posted June 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54670-delete-code-error/ Share on other sites More sharing options...
btherl Posted June 8, 2007 Share Posted June 8, 2007 You need to connect to the database first. Also change the following line so you can see errors: $result = mysql_query("SELECT * FROM `uploaded_files` WHERE `date_added` <= ".$stamp) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/54670-delete-code-error/#findComment-270401 Share on other sites More sharing options...
graham23s Posted June 8, 2007 Author Share Posted June 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54670-delete-code-error/#findComment-270687 Share on other sites More sharing options...
MemphiS Posted June 8, 2007 Share Posted June 8, 2007 $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'"); Quote Link to comment https://forums.phpfreaks.com/topic/54670-delete-code-error/#findComment-270688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.