Jump to content

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

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.