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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.