Lisa23 Posted September 17, 2010 Share Posted September 17, 2010 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 <?phpdefine('ROOT_DIR', './');define('PROPER', TRUE);/*** include common files*/include_once(ROOT_DIR. 'includes/common.inc.php');// No album id has been selectedif (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>"; }?> try 2 error line 5 <?phpdefine('ROOT_DIR', './');define('PROPER', TRUE);/*** include common files*/include_once(ROOT_DIR. 'includes/common.inc.php');// No album id has been selectedif (isset($_GET['albums'])) { // get the image file name so we // can delete it from the server $sql = "SELECT album_id, album_name, album_owner, sub_album FROM albums WHERE album_id = {$_GET['albums']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); // get the image filenames first so we can delete them // from the server $sql = "SELECT photo_id, photo_proper FROM photos WHERE photo_id = {$_GET['photos']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); define("GALLERY_IMG_DIR", "./photos/"); // remove the image and the thumbnail from the server unlink(GALLERY_IMG_DIR . $row['photo_proper']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']); // and then remove the database entry $sql = "DELETE FROM photos WHERE photo_id = {$_GET['photos']}"; $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>"; }}}?> Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/ Share on other sites More sharing options...
MiCR0 Posted September 17, 2010 Share Posted September 17, 2010 Quick Look Line: 21 missing ; Line: 37 missing ; Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112012 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 do u mean on try 2 or 1??? if on try 2 thanks i put the ; signs but now error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\rookierods\deletealbum.php on line 40 Cannot delete a non-existent album. Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112013 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 HELLLP ANYONE Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112035 Share on other sites More sharing options...
rwwd Posted September 17, 2010 Share Posted September 17, 2010 Hi there, Which one are you currently using? 1 or two, if we know which version you are using we can suggest alternative ways or help you understand the issue a little better. Also, it would be most advantageous if you were to use error_reporting(E_ALL); at the top of all your php files, then you would have had the two missing colon's flagged up from the first example. Rw Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112052 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 well i've been wrking on both cz i keep making changes till one of them get to wrk so if u can look in either and se the one that makes more since then i will take upon ur advises help please?? Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112100 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 Lisa... are you using MyIsam or Innodb storage engine for those tables? If you are using Innodb (the default is MyIsam) is not need to implement the code to do cascade deletes because those can be implemented directly in the table(s) definition using FOREIGN KEY and ON DELETE CASCADE constrains. In that way you code should only delete the record(s) in the parent table (and control for possible errors). Maybe this is something that you should look at if you want to learn other alternative. Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112114 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 not quite sure what all that u said means but i have this one which i use to delete photos and remove photos from directory wrks fine so i just thought i had sum other things for the album this the delete photos <?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['photos'])) { // get the image file name so we // can delete it from the server $sql = "SELECT photo_id, photo_proper FROM photos WHERE photo_id = {$_GET['photos']}"; $result = mysql_query($sql) or die('Delete photo failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); define("GALLERY_IMG_DIR", "./photos/"); // remove the image and the thumbnail from the server unlink(GALLERY_IMG_DIR . $row['photo_proper']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']); // and then remove the database entry $sql = "DELETE FROM photos WHERE photo_id = {$_GET['photos']}"; echo '<p>Delete sucessfull click <a href="photos.php">here</a> to return to main menu</p>'; mysql_query($sql) or die('deletd photo failed. ' . mysql_error()); } } else{ } ?> so i modify for the album but nope nt wrking Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112123 Share on other sites More sharing options...
litebearer Posted September 17, 2010 Share Posted September 17, 2010 perhaps... /* This presumes - $_GET['albums'] contains the valid id of an album photo_proper contains the full image name and path */ $what_album = $_GET['albums']; /* loop thru photos unlinking each photo listed as in the target album */ $query0 = "SELECT * FROM photos WHERE album_id = $what_album"; $result0 = mysql_query($query0); WHILE($row = mysql_fetch_array($result0)) { $what_image = $row['photo_proper']; unlink $what_image; } $query1 = "DELETE FROM photos WHERE album_id='$what_album']; $result1 = mysql_query($query1); $query = "DELETE FROM albums WHERE album_id='$what_album']; $result2 = mysql_query($query2); Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112125 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 not quite sure what all that u said means ok... never mind. try this code or starting from litebearer posted adjust yours <?php error_reporting(E_ALL); ini_set("display_errors", 1); define('ROOT_DIR', './'); define('PROPER', TRUE); define("GALLERY_IMG_DIR", "./photos/"); /** * include common files */ include_once(ROOT_DIR. 'includes/common.inc.php'); // No album id has been selected if (isset($_GET['albums'])) { // get the image file name so we // can delete it from the server $sql = "SELECT album_id, album_name, album_owner, sub_album FROM albums WHERE album_id = {$_GET['albums']}"; $result = mysql_query($sql) or die('Album Selection failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); // get the image filenames first so we can delete them // from the server $psql = "SELECT photo_id, photo_proper FROM photos WHERE album_id = {$row['album_id']}"; $presult = mysql_query($psql) or die('Photo Selection failed. ' . mysql_error()); while ($prow = mysql_fetch_assoc($presult)) { // remove the image and the thumbnail from the server unlink(GALLERY_IMG_DIR . $prow['photo_proper']); unlink(GALLERY_IMG_DIR . 'thumbs/' . $prow['photo_proper']); } // and Now we remove the database entries $sql = "DELETE FROM photos WHERE album_id = {$row['album_id']}"; mysql_query($sql) or die('Delete of Album associated photos failed. ' . mysql_error()); $sql = "DELETE FROM album WHERE album_id = {$row['album_id']}"; mysql_query($sql) or die('Delete album failed. ' . mysql_error()); // album deleted successfully, let the user know about it echo "<p align=center>Album $row['album_name'] deleted.</p>"; } else { echo "<p align=center>Cannot delete a non-existent album.</p>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112126 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 i tried urs Offline mikosiko Enthusiast result Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\rookierods\deletealbum.php on line 56 this line echo "<p align=center>Album $row['album_name'] deleted.</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112128 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 perhaps... /* This presumes - $_GET['albums'] contains the valid id of an album photo_proper contains the full image name and path */ $what_album = $_GET['albums']; /* loop thru photos unlinking each photo listed as in the target album */ $query0 = "SELECT * FROM photos WHERE album_id = $what_album"; $result0 = mysql_query($query0); WHILE($row = mysql_fetch_array($result0)) { $what_image = $row['photo_proper']; unlink $what_image; } $query1 = "DELETE FROM photos WHERE album_id='$what_album']; $result1 = mysql_query($query1); $query = "DELETE FROM albums WHERE album_id='$what_album']; $result2 = mysql_query($query2); i tried urs litebearer error Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\rookierods\deletealbum.php on line 40 this how i put it <?php error_reporting(E_ALL); ini_set("display_errors", 1); define('ROOT_DIR', './'); define('PROPER', TRUE); define("GALLERY_IMG_DIR", "./photos/"); /** * include common files */ include_once(ROOT_DIR. 'includes/common.inc.php'); /* This presumes - $_GET['albums'] contains the valid id of an album photo_proper contains the full image name and path */ $what_album = $_GET['albums']; /* loop thru photos unlinking each photo listed as in the target album */ $query0 = "SELECT * FROM photos WHERE album_id = $what_album"; $result0 = mysql_query($query0); WHILE($row = mysql_fetch_array($result0)) { $what_image = $row['photo_proper']; unlink $what_image; } $query1 = "DELETE FROM photos WHERE album_id='$what_album']; $result1 = mysql_query($query1); $query = "DELETE FROM albums WHERE album_id='$what_album']; $result2 = mysql_query($query2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112131 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 Lisa... you have to stick with one version and try to find the problem...posting 2 codes don't help to the people trying to help you... so... change this line echo "<p align=center>Album $row['album_name'] deleted.</p>"; echo "<p align=center>Album {$row['album_name']} deleted.</p>"; if that doesn't fix the problem look for unmatched { or ) or missing ; Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112139 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 Lisa... you have to stick with one version and try to find the problem...posting 2 codes don't help to the people trying to help you... so... change this line echo "<p align=center>Album $row['album_name'] deleted.</p>"; echo "<p align=center>Album {$row['album_name']} deleted.</p>"; if that doesn't fix the problem look for unmatched { or ) or missing ; sorry about that ok i changed that echo line but now it deletes evrything but gives this notice Notice: Use of undefined constant THIS_SCRIPT - assumed 'THIS_SCRIPT' in C:\xampp\htdocs\rookierods\includes\common.inc.php on line 154 which on the common .inc.php is this line if (in_array(THIS_SCRIPT, $access_pages)) the whole part is like this if (in_array(THIS_SCRIPT, $access_pages)) { if ($mode == "new" || THIS_SCRIPT == 'newsletter' || THIS_SCRIPT == 'admin') { // start a session session_start(); if (!isset($_SESSION['logged_in'])) { header("location:" .ROOT_DIR. "login.php"); exit(); } } } Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112146 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 so the code that we were working on is working fine ... good this is a different problem.. as we don't know what do you have in your common.inc.php we can only guess what the problem could be... try changing THIS_SCRIPT for $THIS_SCRIPT in all the places. otherwise, post your common.inc.php code Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112150 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 so the code that we were working on is working fine ... good this is a different problem.. as we don't know what do you have in your common.inc.php we can only guess what the problem could be... try changing THIS_SCRIPT for $THIS_SCRIPT in all the places. otherwise, post your common.inc.php code issue on this line if (in_array(THIS_SCRIPT, $access_pages)) this is the comon.inc.php <?php /** * check for hacking attempt */ if (!defined("PROPER")) { die("hacking attempt"); } /** * deal with backwards compatibility */ if (!isset($_SERVER)) { $_GET = &$HTTP_GET_VARS; $_POST = &$HTTP_POST_VARS; $_SERVER = &$HTTP_SERVER_VARS; $_COOKIE = &$HTTP_COOKIE_VARS; $_SESSION = &$HTTP_SESSION_VARS; } /** * what globals are allowed */ $allowed_globals = array( 'GLOBALS', '_POST', '_GET', '_FILES', '_REQUEST', '_SERVER', '_COOKIE', '_SESSION', 'allowed_globals' ); /** * check any globals that are passed * and unset if not allowed */ foreach ($GLOBALS as $key => $value) { if (!in_array($key, $allowed_globals) && $key != 'key' && $key != 'value') { unset($GLOBALS[$key]); } } /** * deal with magic quotes (stripslashes) */ if (get_magic_quotes_gpc()) { function strip_quotes (&$vars) { if (is_array($vars)) { foreach ($vars AS $key => $value) { if (is_string($value)) { $vars[$key] = stripslashes($value); } elseif (is_array($value)) { $vars[$key] = strip_quotes($value); } } } return $vars; } $_GET = strip_quotes($_GET); $_POST = strip_quotes($_POST); $_COOKIE = strip_quotes($_COOKIE); } include_once(ROOT_DIR. "classes/template.class.php"); include_once(ROOT_DIR. "classes/error.class.php"); include_once(ROOT_DIR. "classes/database.class.php"); include_once(ROOT_DIR. "classes/sessions.class.php"); include_once(ROOT_DIR. "includes/constants.inc.php"); /** * setup the database connection */ $db_name = 'eurico_edy'; $db_pass = ''; $db_user = 'root'; $db_host = 'localhost'; if (!$db = new db_handler($db_user, $db_pass, $db_name, $db_host)) { die("COULD NOT CONNECT TO DATABASE"); } /** * setup style */ if (!$template = new template(ROOT_DIR)) { die("COULD NOT INITIALISE TEMPLATE ENGINE"); } /** * begin error handling */ if (!$errors = new error_handler()) { die("COULD NOT INITIALISE ERROR HANDLER"); } $sessions = new session_handler(); /** * get the mode */ if (isset($_REQUEST['mode'])) { $mode = trim($_REQUEST['mode']); } else { $mode = ''; } /** * what page are we on? */ if (isset($_REQUEST['page'])) { $page = intval($_GET['page']) - 1; } else { $page = 0; } /** * for certain pages we need to check admin access */ $access_pages = array( 'drivers', 'news', 'newsletter', 'admin' ); if (in_array(THIS_SCRIPT, $access_pages)) { if ($mode == "new" || THIS_SCRIPT == 'newsletter' || THIS_SCRIPT == 'admin') { // start a session session_start(); if (!isset($_SESSION['logged_in'])) { header("location:" .ROOT_DIR. "login.php"); exit(); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112152 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 THIS_SCRIPT is no defined in that code.... check if it is defined in one of the include files .. probably in the constants.inc.php file and disregard my previous suggestion... THIS_SCRIPT most likely is a constant not a variable. Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112155 Share on other sites More sharing options...
litebearer Posted September 17, 2010 Share Posted September 17, 2010 BTW I noticed I forgot the single quotes around $what_album in $query0 Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112158 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 nope not in the constant thsi what i gt in the constant file <?php $table_prefix = ''; /** * define table names */ define('ALBUMS_TABLE', $table_prefix. 'albums'); define('COMMENTS_TABLE', $table_prefix. 'comments'); define('PHOTOS_TABLE', $table_prefix. 'photos'); define('SESSIONS_TABLE', $table_prefix. 'sessions'); define('USERS_TABLE', $table_prefix. 'users'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112163 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 BTW I noticed I forgot the single quotes around $what_album in $query0 litebearer I didnt quite understand what u talking about which line?? Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112166 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 nope not in the constant thsi what i gt in the constant file that should be there... but hard to tell you which value it should have because we don't know the whole system. either you can define it with any value and test what happens or analyze the code completely and try to understand how it work.. from that understanding you should be able ti figure out what value that constant should have... by now your original script is working and the message that you are getting is just a NOTICE. Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112173 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 BTW I noticed I forgot the single quotes around $what_album in $query0 litebearer I didnt quite understand what u talking about which line?? again.... with the due respect for litebearer contribution.... stick with the code that you have now Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112174 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 in the page that is calling the delete page i have define('THIS_SCRIPT', 'photos'); is that why giving the error??? Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112177 Share on other sites More sharing options...
mikosiko Posted September 17, 2010 Share Posted September 17, 2010 write that in your constants.inc.php file and test if you are defining it in the caller page the constant is "unknown" in your delete page Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112186 Share on other sites More sharing options...
Lisa23 Posted September 17, 2010 Author Share Posted September 17, 2010 yeah this was missing on the delete script define('THIS_SCRIPT', 'photos'); Thank you very much working perfectly now Quote Link to comment https://forums.phpfreaks.com/topic/213643-delete-album-and-items-related-to-the-album-help/#findComment-1112190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.