Forum Moderators: coopster
<?php
//connect to the database
$link = mysql_connect("localhost", "admin", "password")
or die("Could not connect: " . mysql_error());
mysql_select_db("gallery", $link)
or die (mysql_error());
$folder_location = $_POST['folder_location'];
$picture_id = $_POST['picture_id'];
$ImageDir = $_POST['ImageDir'];
$ImageThumb = $_POST['ImageThumb'];
$slash = "/";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Delete Image Confirm</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
echo "folder location: <b>$folder_location</b> and picture id: <b>$picture_id</b>";
echo "Image Dir: <b>$ImageDir</b> and ImageThumb: <b>$ImageThumb</b>";
?>
<p align="center">Listing of picture to be deleted</p>
<table align="center">
<?php
$ImageDir = $ImageDir .$slash;
//tell database which folder to display
switch ($folder_location) {
case "centerpieces":
$getpic = mysql_query("SELECT * FROM gallery_centerpieces WHERE image_id=$picture_id")
or die(mysql_error());
while ($rows = mysql_fetch_array($getpic)) {
extract($rows);
echo "<tr>\n";
echo "<td><a href=\"".$ImageDir . $image_id . ".jpg\">";
echo "<img src=\"" . $ImageDir . $image_id . ".jpg\" border=\"0\">";
echo "</a></td>\n";
echo "<td>" . $image_id . "</td>\n";
echo "</tr>\n";
}
break;
<removed a ton of other cases - jatar_k>
}
?>
</table>
<form name="form1" method="post" action="deleted_image_confirmed.php"
enctype="multipart/form-data">
<center><p>Are you sure you want to delete this picture from your gallery?</p>
</center>
<p align="center"><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear Form">
</p>
</form>
</body>
</html>
[edited by: jatar_k at 3:17 pm (utc) on Sep. 13, 2005]
the form doesn't seem to contain any info about the image it is trying to delete and all the images just look like links around them to themselves.
you will need to have a way for the user to select an image, such as starting your form from the top of the page and having a radio button, or something, to enable them to select a certain image. That radio can have the image id or name as its value. That id will then get passed to the processing script on submit.
You can then use that id to issue a delete query to mysql.
If you cant be bothered doing that here is the php / sql.
<?php
$delete = mysq_query("DELETE $rowdata FROM $tablename WHERE $id = $what-you-want-to-delete");
?>
once you select an image and post its id to the next script. The script will then have to have a way to know you want to delete, if it is multifunctional, and what image it is you want to delete.
you would then use the id posted from the form and issue a delete query as Angelis showed.