Hi guys. I keep getting an SQL error when trying to delete an image from a gallery I have been working on for a customer.
I have been building him an image uploader application for his website and I currently have most of the mechanics in place so it functions correctly.
The only thing I need to do is give my client the ability to choose a gallery he wants to delete an image from and and then click a delete link to delete the image.
I have managed to set everything up on his admin page so he can choose an image to delete and then click a delete link.
I have also set things up so when a delete link is clicked, it then triggers a method inside a class.
This method is pasted below:
public static function deleteimage( $deleteimggallery, $deleteimg ) {
$conn = parent::connect();
$sql = "DELETE FROM :deleteimggallery WHERE img_name = :deleteimg";
try{
$st = $conn->prepare($sql);
$st->bindValue(":deleteimggallery", $deleteimggallery, PDO::PARAM_STR);
$st->bindValue(":deleteimg", $deleteimg, PDO::PARAM_STR);
$st->execute();
}catch(PDOException $e){
parent::disconnect($conn);
die( "query failed: " . $e->getMessage() );
}
}
...... and I keep getting the following error message:
query failed: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''paths' WHERE img_name = '201707112136247.jpg'' at line 1
And I can't figure out how to fix it.
By the way,,, just to let you know ( in the above error ),,, ''paths' is the name of one of the galleries tables and 'img_name' is one of the columns inside each gallery table.
Also, the 2 parameters passed to the method (above):
$deleteimggallery, $deleteimg
.... hold the image gallery name and the image name (to delete), respectively.
Paul.