am trying to allow a user to delete a certain image with is in a certain directory. I need them to first specify a directory and then the image which they want to delete.
I have been able to accomplish what I thought would be the hard part, of having their Gallery selection result in a drop-down populated only with the name of those images in their selected gallery.
My issue is that I cannot seem to get the submit button for my second form to trigger the if statement that will delete the files and remove the row from the table. I thought someone here might peruse my code and tell me what I am missing 🙁
thanks a ton!
<form action ='' name="form1" method='POST' enctype="multipart/form-data">
<p>Select Gallery: <select name="gal" style="color:black;">
<option value="" style="color:black;"><?php echo $gal; ?></option>
<option value="graphicdesign/logos" style="color:black;">GD logos</option>
<option value="graphicdesign/webdesign" style="color:black;">GD website design</option>
<option value="graphicdesign/advertisements" style="color:black;">GD Advertisements</option>
<option value="fineart/nature" style="color:black;">FA Nature</option>
<option value="fineart/people" style="color:black;">FA People</option>
<option value="fineart/landscapes" style="color:black;">FA Landscapes</option>
<option value="photography/misc" style="color:black;">PG Misc</option>
<option value="photography/nature" style="color:black;">PG Nature</option>
<option value="photography/people" style="color:black;">PG People</option>
</select></p>
<input type="submit" value="Set Galery" style="color:black;"></p>
<?php
$connect = mysql_select_db("cynthie") or die("couln't find db on 2 :(");
$metaData = mysql_query("SELECT `name`, `path_full`, `path_thumb`, `galId` FROM `images`") or die("couln't find table :(");
$gal = $_POST['gal'];
if (isset($_POST['gal']))
{
echo '<form action ="" method="POST" enctype="multipart/form-data"><p>Select Image: <select name="toDelete" style="color:black;"><p><option style="color:black;">select img</option></p>';
while ($displayData = mysql_fetch_assoc($metaData))
{
$names = $displayData['name'];
$path_full = $displayData['path_full'];
$path_thumb = $displayData['path_thumb'];
$galDb = $displayData['galId'];
if ($galDb != $gal)
{}
else
{
echo '<p><option style="color:black;">'.$names.'</option></p>';
}
}
echo '</select><p><input type="submit" value="Delete" style="color:black;"></p></form>';
$connect = mysql_select_db("cynthie") or die("couln't find db on 4 :(");
$delete = mysql_query("SELECT `id` FROM images WHERE name='$toDelete'") or die("couln't find table on line 81 :(");
$toDelete = $_POST['toDelete'];
if (isset($_POST['toDelete']))
{
unlink($path_full);
unlink($path_thumb);
mysql_query("DELETE FROM images WHERE `id`=$delete");
unset($delete);
echo '<p>removed!</p>';
}
else
{}
}
?>
You have your
toDeletecheck inside thegalcheck, so you need to have$_POST['gal']and$_POST['toDelete']being sent. I don’t seegalin your second form, so just add<input type="hidden" name="gal" value="{$_POST['gal']}" />.