PHP & MySQL Image deletion problem?
        Posted  
        
            by IMAGE
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by IMAGE
        
        
        
        Published on 2010-04-17T00:57:27Z
        Indexed on 
            2010/04/17
            1:03 UTC
        
        
        Read the original article
        Hit count: 310
        
I have this script that deletes a users avatar image that is stored in a folder name thumbs and another named images and the image name is stored in a mysql database.
But for some reason the script deletes all the users info for example if the users id is 3 all of the users info like first name last name age and so are deleted as well, basically everything is deleted including the user how do I fix this so only the images and image name is deleted?
Here is the code.
$user_id = '3';
if (isset($_POST['delete_image'])) { 
    $a = "SELECT * FROM users WHERE avatar = '". $avatar ."' AND user_id = '". $user_id ."'";
    $r = mysqli_query ($mysqli, $a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($mysqli));
    if ($r == TRUE) {           
        unlink("../members/" . $user_id . "/images/" . $avatar); 
        unlink("../members/" . $user_id . "/images/thumbs/" . $avatar);
        $a = "DELETE FROM users WHERE avatar = '". $avatar ."' AND user_id = '". $user_id ."'";
        $r = mysqli_query ($mysqli, $a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($mysqli));
    }
}
© Stack Overflow or respective owner