i do think is a small mistake i making can u please have a look if u can
ok here's the problem i am trying to delete an album within the album should also delete the photos related to that album this what i tried gives this error
Delete image 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
my tables are
table albums fields album_id, album_name, album_owner, sub_album
table photos fields, photo_id, photo_name, photo_extension, photo_proper photo_owner, photo_date, photo_comments, photo_size, album_id
photo_proper is the name image stored in folder
<?php
define('ROOT_DIR', './');
define('PROPER', TRUE);
/**
* include common files
*/
include_once(ROOT_DIR. 'includes/common.inc.php');
// No album id has been selected
if (isset($_GET['albums']))
// get the album name since we need to display
// a message that album 'foo' is deleted
$result = mysql_query("SELECT album_id, album_name, album_owner, sub_album
FROM albums
WHERE album_id = $album_id")
or die('Delete image failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$album_id = $row['album_id'];
$album_name = $row['album_name'];
// get the image filenames first so we can delete them
// from the server
$result = mysql_query("SELECT photo_id, photo_id
FROM photos
WHERE album_id = $album_id")
or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
define("GALLERY_IMG_DIR", "./photos/");
unlink(GALLERY_IMG_DIR . $row['photo_proper']);
unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']);
}
$result = mysql_query("DELETE FROM photos
WHERE album_id = $album_id")
or die('Delete image failed. ' . mysql_error());
$result = mysql_query("DELETE FROM album
WHERE album_id = $album_id")
or die('Delete album failed. ' . mysql_error());
// album deleted successfully, let the user know about it
echo "<p align=center>Album '$album_name' deleted.</p>";
} else {
echo "<p align=center>Cannot delete a non-existent album.</p>";
}
?>
second method error line 5
<?php
define('ROOT_DIR', './');
define('PROPER', TRUE);
/**
* include common files
*/
include_once(ROOT_DIR. 'includes/common.inc.php');
// No album id has been selected
if (isset($_GET['albums']))
// get the album name since we need to display
// a message that album 'foo' is deleted
$result = mysql_query("SELECT album_id, album_name, album_owner, sub_album
FROM albums
WHERE album_id = $album_id")
or die('Delete image failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$album_id = $row['album_id'];
$album_name = $row['album_name'];
// get the image filenames first so we can delete them
// from the server
$result = mysql_query("SELECT photo_id, photo_id
FROM photos
WHERE album_id = $album_id")
or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
define("GALLERY_IMG_DIR", "./photos/");
unlink(GALLERY_IMG_DIR . $row['photo_proper']);
unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']);
}
$result = mysql_query("DELETE FROM photos
WHERE album_id = $album_id")
or die('Delete image failed. ' . mysql_error());
$result = mysql_query("DELETE FROM album
WHERE album_id = $album_id")
or die('Delete album failed. ' . mysql_error());
// album deleted successfully, let the user know about it
echo "<p align=center>Album '$album_name' deleted.</p>";
} else {
echo "<p align=center>Cannot delete a non-existent album.</p>";
}
?>