473,412 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Updating data in database without losing image name

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
1 1385
xwero
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

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

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
2
by: mdulaney | last post by:
I have a front end database file linked to a back end database file. Periodically (every few months?), a form name frmStallSvcContract which is based on a query comes up without data. The fields...
0
by: kaosyeti | last post by:
this is a really weird issue for me to try to explain but i'll do my best. i started writing a db for my store in september to track customer flow. at that time, i gave a copy to 3 other of our...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
by: Shogun | last post by:
Hey guys, i'm trying to do a confirmation msgbox asking the user if he's sure about updating his database. The problem is... wathever the answer (Yes/No), the database is updated anyway! My code is...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.