I have two tables:
Table: photo_gallery_cat
phcat_id: 1
category: Beautiful Estates
phcat_id: 2
category: Ugly Estates
Table: photo_gallery
pg_id: 1
phcat_id: 1
larg_img: lib_jog.jpg
pg_id: 2
phcat_id: 1
larg_img: wea_sel.jpg
What I would like to do is to be able to delete a set of images based upon a category selected from photo_gallery and also the ability to delete the category as well from the photo_gal_cat table.
This what I have so far:
$colname_getGallery = "-1";
if (isset($_GET['phcat_id'])) {
$colname_getGallery = $_GET['phcat_id'];
mysql_select_db(myconnectionstuff);
$query_getGallery = sprintf("SELECT photo_gallery_cat.category, photo_gallery.pg_id, photo_gallery.phcat_id, photo_gallery.larg_img FROM photo_gallery JOIN photo_gallery_cat ON photo_gallery.phcat_id = photo_gallery_cat.phcat_id WHERE photo_gallery.phcat_id = %s", GetSQLValueString($colname_getGallery, "int"));
$getGallery = mysql_query($query_getGallery, $CVconn) or die(mysql_error());
$row_getGallery = mysql_fetch_assoc($getGallery);
$totalRows_getGallery = mysql_num_rows($getGallery);
if (array_key_exists('cancel', $_POST)) {
header('Location: list.php');
exit;
}
if ((isset($_POST['phcat_id'])) && ($_POST['phcat_id'] != "")) {
$deleteSQL = sprintf("DELETE FROM photo_gallery WHERE phcat_id=%s",
GetSQLValueString($_POST['phcat_id'], "int"));
unlink("../../photos/". $row_getGallery['larg_img']);
mysql_select_db($database_CVconn, $CVconn);
$Result1 = mysql_query($deleteSQL, $CVconn) or die(mysql_error());
$deleteGoTo = "delete_gallery_list.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));