I'm experiencing an issue deleting data via PHP/MySQL query.
The following is the error message:
Delete product category failed. 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 '' at line 3
This is the PHP code that I'm using:
<?php
if (isset($_GET['delete']) && isset($_GET['album']) && isset($_GET['imgId'])) {
// get the image file name so we
// can delete it from the server
$sql = "SELECT im_image, im_thumbnail
FROM tbl_image
WHERE im_id = {$_GET['imgId']} AND im_album_id = {$_GET['album']}";
$result = mysql_query($sql) or die('Delete product category failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
// remove the image and the thumbnail from the server
unlink(GALLERY_IMG_DIR . $row['im_image']);
unlink(GALLERY_IMG_DIR . 'thumbnail/' . $row['im_thumbnail']);
// and then remove the database entry
$sql = "DELETE FROM tbl_image
WHERE im_id = {$_GET['imgId']} AND im_album_id = {$_GET['album']}";
mysql_query($sql) or die('Delete product category failed. ' . mysql_error());
}
}
$imagePerPage = 10;
$album = isset($_GET['album']) ? $_GET['album'] : '';
$pageNumber = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;
$offset = ($pageNumber - 1) * $imagePerPage;
$serial = $offset + 1;
// get album list
$sql = "SELECT al_id, al_name
FROM tbl_album
ORDER BY al_name";
$result = mysql_query($sql) or die('Error, get product category list failed : ' . mysql_error());
$albumList = '';
while ($row = mysql_fetch_assoc($result)) {
$albumList .= '<option value="' . $row['al_id'] . '"' ;
if ($row['al_id'] == $album) {
$albumList .= ' selected';
}
$albumList .= '>' . $row['al_name'] . '</option>';
}
?>
The line 3 of the code is this:
if (isset($_GET['delete']) && isset($_GET['album']) && isset($_GET['imgId'])) {
Your help will always be appreciated.