Jump to content

I need coffee NOW!


one.time.loser

Recommended Posts

My brain hurt from the following snippet, i've been cramming php/mysql for 2 weeks now with many headaches on the way. Gone from Zero to Hero, now back to Zero. Imagine a 5 field table;

1.  Id              //Nuff Said
2.  Submitted  //TimeStamp
3.  Title          //Duh
4.  Description //Double Duh
5.  Image      //Image Name URL

It use to be only 4 , with image being a new field. The old way of removing old records was;

$sql = mysql_query("DELETE from free where submitted < date_sub(now(), interval (8) day)") or die(mysql_error());

Now i tried writing it like this;

if($action=='delete')
    {
        $image_dir="./admin/images/";


        //Deleting image from directory
        $sql = mysql_query("SELECT from free where submitted < date_sub(now(), interval (8) day)") or die(mysql_error());
        $row = mysql_fetch_row($query);
        $image=$row[image];
        $image_dir.=$image;
        chmod($image_dir,0777);
       
        if (file_exists($image_dir))
        {
            unlink($image_dir);// or die ("Could not delete file");
        }
       
        $sql = mysql_query("DELETE from free where submitted < date_sub(now(), interval (8) day)") or die(mysql_error());
    }

As i am a member of 8 different forums now, i haven't got a definitive answer yet. So the learning curve is currently running down hill at a 90 degree angle. Where i went wrong, i have no idea, only because i really  dont have much to go on.

Pls take the time someone and show me where i went wrong, and if not! Then get me some COFFEE please!
Link to comment
https://forums.phpfreaks.com/topic/30107-i-need-coffee-now/
Share on other sites

There are no visible errors, the record gets deleted yet the image is still on the server. The image path is correct and the attributes of the folder. This is my first attempt at writing a script to query the table for an expired record, then delete the image, then delete the record. If the formatting of the above is correct please let me know, it may be an entirely different problem.
Link to comment
https://forums.phpfreaks.com/topic/30107-i-need-coffee-now/#findComment-138698
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.