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