By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,824 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,824 IT Pros & Developers. It's quick & easy.

Updating data in database without losing image name

P: 1
I have a page that allows users to update their data. One of the items of data is an image.

Therefore the update page includes an <input type="file"> field to allow them to choose a different image.

The problem is, that if the user does not want to change the image and leaves this field blank, when they press the submit button, it updates the database and removes the name of the previous image the user had uploaded.

There are 5 images in the update form.

Here is the update code I have at the moment:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $sql = "UPDATE businesslistingtb SET companyname='$companyname', address='$address' , postcode='$postcode' , 
  3.  
  4. contactname='$contactname' , contactnumber='$contactnumber' , email='$email' , businesstype='$businesstype' , businesshours='$businesshours' 
  5.  
  6. , whatsunique='$whatsunique' , logo_image='$imagename', testimonial1text='$testimonial1text' , testimonial1who='$testimonial1who' , 
  7.  
  8. testimonial2text='$testimonial2text' , testimonial3text='$testimonial3text' , products='$products' , services='$services' , awards='$awards' 
  9.  
  10. , directions='$directions' , paymentmethods='$paymentmethods' , additionalinfo='$additionalinfo' , gallery_image1='$gallery_image1_name' , 
  11.  
  12. gallery_image2='$gallery_image2_name' , gallery_image3='$gallery_image3_name' , gallery_image4='$gallery_image4_name' WHERE userid=$id";
  13.  
  14.  

Any help much appreciated!

Paul
Feb 9 '07 #1
Share this Question
Share on Google+
1 Reply


P: 99
You should break up your sql statement and check if an image is uploaded or not. If it is then you add the name to the sql statement

[PHP]
$mysql = 'update table set ';
if(count($_FILES['image']) > 0){
$mysql .= 'imagename = "'.$_FILES['image']['name'];
}
$mysql .= ' where id = 1';
[/PHP]
Feb 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.