Jump to content

Removing an image


jonw118

Recommended Posts

I'd appreciate any help someone could lend!

 

Basically I have a script that shows 1 image. Under it is a remove button.

 

Here is the remove code for it on the page:

 

<? if(!empty($row2['image'])) { ?>

<img src="<? echo $row2['thumb'];?>"> <a href="remove_image.php?id=<? echo $row2['id'];?>">Remove Image</a>
<? }
else {
?>
<input type="file" name="photo1"> 
<? }?>

 

So, when you remove an image it calls remove_image.php:

<?
include ("define.php");
$sql="update inputinfo set image='',thumb='' where id='$id'";
$rez=mysql_query($sql,$dblnk);
header('location: edit.php?id='.$id);
?>

 

Simple enough. But, here's my problem. I added two more pics into the database.

 

For the new images that are uploaded to the database I am using the following (which displays fine):

 

<? if(!empty($row2['image2'])) { ?>
<img src="<? echo $row2['thumb2'];?>"> <a href="remove_image.php?id=<? echo $row2['id'];?>">Remove Image</a>
<? }
else {
?>
<input type="file" name="photo2"> 
<? }?>

 

and

 

<? if(!empty($row2['image3])) { ?>
<img src="<? echo $row2['thumb3'];?>"> <a href="remove_image.php?id=<? echo $row2['id'];?>">Remove Image</a>
<? }
else {
?>
<input type="file" name="photo3"> 
<? }?>

 

But #2 & #3 will not delete correctly. Sometimes they do, sometimes they don't. Depends if previous images and such are deleted.

 

That remove_image.php was updated to (and I know my problem is in here). Seems like it stalls out on this script for some reason:

 

<?
include ("define.php");
$sql="update inputinfo set image='',thumb='' where id='$id'";
$sql="update inputinfo set image2='',thumb2='' where id='$id'";
$sql="update inputinfo set image3='',thumb3='' where id='$id'";
$rez=mysql_query($sql,$dblnk);
header('location: edit.php?id='.$id);
?>

 

Is there something I am missing that should inserted in between each line of $sql?

 

Again, I'd really appreciate some advise!

Link to comment
https://forums.phpfreaks.com/topic/139764-removing-an-image/
Share on other sites

Hey jonw118,

 

It is becuase you are re-defining $sql each time.

 

So if you wanted to do it the way you had setup you would need to run

$rez=mysql_query($sql,$dblnk);

after each $sql you have setup.

 

I suggest combining the queries together, something like this:

$sql="update inputinfo set image='',thumb='', image2='', thumb2='', image3='', thumb3='' where id='$id'";

 

Hope that helps! :)

Link to comment
https://forums.phpfreaks.com/topic/139764-removing-an-image/#findComment-731218
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.