Reputation: 3
here is my unlink code to delete a image out of the server folder it is working but it deletes the news image in the folder and not the one that is associate with the image_id or the image_path so how do I tell it to delete the image for the image_id or image_path?
<?php
if (isset($_POST['submit'])) {
$res = mysql_query("select * from record_images where image_id=image_id");
while ($row = mysql_fetch_array($res)) {
$image_name = $row["image_path"];
}
unlink($image_name);
}
?>
Here is my new code and it works good. OOPS I made a mistake it will delete the images that are associated to the image_id but it deletes the images in the server folder too soon when I click on the link in the Edit page it sends me to the Delete page and it will delete the image at that time and thin I have to click the Delete button to delete the criteria for that image_id in the database and I don't want that to happen. I don't want the image in the server folder to be delete until I click the Delete button in the Delete page
<?php
if (isset($_GET['image_id']))
{
$res=mysql_query("SELECT * From record_images where image_id=".$_GET['image_id']);
while($row=mysql_fetch_array($res))
{
$image_name=$row["image_path"];
$thnimage_name=$row["thumbnail_path"];
}
unlink($image_name);
unlink($thnimage_name);
}
?>
So here is my new new code. now it will delete the images in the server folder when I click on the Delete button in the Delete page and not before. and I had to add this image_id to the rest of the criteria for the Delete button
<?php
if ((isset($_POST['submit'])) && ($_POST['image_id'] != ""))
{
$res=mysql_query("SELECT * From record_images where image_id=".$_GET['image_id']);
while($row=mysql_fetch_array($res))
{
$image_name=$row["image_path"];
$thnimage_name=$row["thumbnail_path"];
}
unlink($image_name);
unlink($thnimage_name);
}
?>
here is what my Delete button code looks like with the added criteria
<form id="form1" name="form1" method="post" action="/finditlogit/private/sites/logs/artifacts/records/photo_gallery/delete.php?
site_id=<?php echo $row_rssites['site_id']; ?>
&block_id=<?php echo $row_rsarchitectural_blocks['block_id']; ?>
&log_id=<?php echo $row_rslogs['log_id']; ?>
&record_id=<?php echo $row_rsrecords['record_id']; ?>
&image_id=<?php echo $row_rsrecord_images['image_id']; ?>
&site_criteria=<?php echo htmlspecialchars ($site_criteria, ENT_QUOTES); ?>
&site_attributes=<?php echo htmlspecialchars ($site_attributes, ENT_QUOTES); ?>
&block_criteria=<?php echo htmlspecialchars ($block_criteria, ENT_QUOTES); ?>
&block_attributes=<?php echo htmlspecialchars ($block_attributes, ENT_QUOTES); ?>
&logs_criteria=<?php echo htmlspecialchars ($logs_criteria, ENT_QUOTES); ?>
&log_criteria=<?php echo htmlspecialchars ($log_criteria, ENT_QUOTES); ?>
&log_attributes=<?php echo htmlspecialchars ($log_attributes, ENT_QUOTES); ?>">
<input type="submit" name="submit" value="Delete" />
<input name="image_id" type="hidden" id="image_id" value="<?php echo $row_rsrecord_images['image_id']; ?>" />
</form>
Upvotes: 0
Views: 62
Reputation: 979
Your query fetches all the records since you're saying where image_id = image_id
.
Should the image_id
be a variable or something?
The $image_name = $row["image_path"];
will then be the value of the last record in the table, resulting in that image being deleted.
Upvotes: 2