473,387 Members | 1,517 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,387 software developers and data experts.

Updating an image

I have a php application which has a page where some personal details
can be updated. One of the details is a photo.
The backend is mysql.

My question has to do with how best to code for this. Since the image
is not changed often, do I have 2 mysql update statements in the code?

Something like this

$var1 = $_FILES['photo']['name'];

if ($var1)
{ sql update statement that includes the photo column as
well}
else
{sql update statement that doesn't include the photo column}

Is there another approach to accomplish this?
Jun 27 '08 #1
6 1556
sumithar wrote:
I have a php application which has a page where some personal details
can be updated. One of the details is a photo.
The backend is mysql.

My question has to do with how best to code for this. Since the image
is not changed often, do I have 2 mysql update statements in the code?

Something like this

$var1 = $_FILES['photo']['name'];

if ($var1)
{ sql update statement that includes the photo column as
well}
else
{sql update statement that doesn't include the photo column}

Is there another approach to accomplish this?
Yes and no. Yes, that is one way. No, since this is for an existing
entry (you are using UPDATE), you obviously have already done a select
to get the existing properties. Pull in the photo location with that
call and put its value in some variable. If you do a new upload of a
photo to replace it, then change that variable's value. Then all you
have to do is do the update with that variable's value.
Jun 27 '08 #2
On 11 Jun, 15:25, sumithar <Rasha...@gmail.comwrote:
I have a php application which has a page where some personal details
can be updated. *One of the details is a photo.
The backend is mysql.

My question has to do with how best to code for this. *Since the image
is not changed often, do I have 2 mysql update statements in the code?

Something like this

*$var1 = $_FILES['photo']['name'];

*if ($var1)
* * * * * { *sql update statement that includes the photo column as
well}
*else
* * * * * {sql update statement that doesn't include the photo column}

Is there another approach to accomplish this?
I tend to code using the INSERT INTO ... SET ... ON DUPLICATE KEY
UPDATE ...
syntax (of MySQL). Where I actually store the contents of a file in
the database (in a BLOB field), in response to a possible file upload,
my code only includes the LOAD_FILE(contents) part of the statement,
if I actually have that to insert. Since I am building the query
dynamically, it is up to me whether or not it includes that part of
the statement. This is true for any database SQL syntax. If you build
the query dynamically you get to choose what goes in it.
Jun 27 '08 #3
sumithar wrote:
I have a php application which has a page where some personal details
can be updated. One of the details is a photo.
The backend is mysql.

My question has to do with how best to code for this. Since the image
is not changed often, do I have 2 mysql update statements in the code?

Something like this

$var1 = $_FILES['photo']['name'];

if ($var1)
{ sql update statement that includes the photo column as
well}
else
{sql update statement that doesn't include the photo column}

Is there another approach to accomplish this?
Maybe. So you already have the photo filename, i.e. from a previous
SELECT statement? If so, you can just insert it as the default value,
then if they upload a new photo, replace the default value with the new
one. Then go ahead and update the database. It won't hurt to update a
a column with the same data which was already there (in fact, MySQL will
ignore a such a change for that column).

If you don't already have the photo filename, then go ahead and use a
second UPDATE statement. It will be better than having to fetch just
the photo filename so you can (not) change it.

Or, create an object for the table which does this for you :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #4
sumithar wrote:
I have a php application which has a page where some personal details
can be updated. One of the details is a photo.
The backend is mysql.

My question has to do with how best to code for this. Since the image
is not changed often, do I have 2 mysql update statements in the code?

Something like this

$var1 = $_FILES['photo']['name'];

if ($var1)
{ sql update statement that includes the photo column as
well}
else
{sql update statement that doesn't include the photo column}

Is there another approach to accomplish this?
I update images entirely sperately, depending on whether the $_FILES
array has anything in it.

Its easy enough to check

Jun 27 '08 #5
On Jun 11, 2:33*pm, The Natural Philosopher <a...@b.cwrote:
sumithar wrote:
I have a php application which has a page where some personal details
can be updated. *One of the details is a photo.
The backend is mysql.
My question has to do with how best to code for this. *Since the image
is not changed often, do I have 2 mysql update statements in the code?
Something like this
*$var1 = $_FILES['photo']['name'];
*if ($var1)
* * * * * { *sql update statement that includes the photo column as
well}
*else
* * * * * {sql update statement that doesn't include the photocolumn}
Is there another approach to accomplish this?

I update images entirely sperately, depending on whether the $_FILES
array has anything in it.

Its easy enough to check
Thanks all!

Actually in my initial SELECT to display the values on the form, I
don't include the photo column. I have a separate database call for
that like so:
<img src="dispphoto.php?id="<?php echo $player_id; ?>"" width="80"
height="60">

And dispphoto.php just SELECTs the photo column from the table and
"echo"es it.

Captain- sorry you lost me completely. Dynamic SQL was taboo in the
world I come from ;-)

Jerry- I have just a nodding acquaintance w/ OO-PHP. Are you
suggesting the use of some Object-Relational mapper tool? My java
developer friends use something called Hibernate. Is that what you
are talking about?

Doing the update of image alone as a separate statement looks a good
option based on whether the $_FILES has a value in it. Better than 2
long update statements. Though it will be one DB call extra but this
is a low volume environment.
Jun 27 '08 #6
sumithar wrote:
On Jun 11, 2:33 pm, The Natural Philosopher <a...@b.cwrote:
>sumithar wrote:
>>I have a php application which has a page where some personal details
can be updated. One of the details is a photo.
The backend is mysql.
My question has to do with how best to code for this. Since the image
is not changed often, do I have 2 mysql update statements in the code?
Something like this
$var1 = $_FILES['photo']['name'];
if ($var1)
{ sql update statement that includes the photo column as
well}
else
{sql update statement that doesn't include the photo column}
Is there another approach to accomplish this?
I update images entirely sperately, depending on whether the $_FILES
array has anything in it.

Its easy enough to check

Thanks all!

Actually in my initial SELECT to display the values on the form, I
don't include the photo column. I have a separate database call for
that like so:
<img src="dispphoto.php?id="<?php echo $player_id; ?>"" width="80"
height="60">

And dispphoto.php just SELECTs the photo column from the table and
"echo"es it.

Captain- sorry you lost me completely. Dynamic SQL was taboo in the
world I come from ;-)

Jerry- I have just a nodding acquaintance w/ OO-PHP. Are you
suggesting the use of some Object-Relational mapper tool? My java
developer friends use something called Hibernate. Is that what you
are talking about?

Doing the update of image alone as a separate statement looks a good
option based on whether the $_FILES has a value in it. Better than 2
long update statements. Though it will be one DB call extra but this
is a low volume environment.
Nor familiar with Hibernate. You should learn about OO programming.
There are a number of books out there.

Remember - OO is a design methodology - and is, as such, relatively
language independent (as long as you have a language which supports OO).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vladimir Kanovnik | last post by:
I have table with columns id(number), photo(blob) and thumbnail(blob). I would like to insert image (using stored procedure) from file to column photo and in same time copy reduced image to column...
2
by: billrdio | last post by:
I am trying to make a JavaScript animation of real-time images - i.e. images that will periodically change on the server. The problem I am having is that the JavaScript animation I have created is...
5
by: Mike Dole | last post by:
When I am updating a picturebox with an image (extracted) from an access database I keep getting a "The process cannot access the file "c:\foto1.jpg because it is being used by another process"...
2
by: thehuby | last post by:
I am building a CMS and as part of it a user can upload an image. Once uploaded I am displaying the image. If the user then decides they want to replace the image with another I get a caching...
4
by: Jerry West | last post by:
I have a routine that updates a PictureBox image every x seconds. I do this by first loading an array with the path to all of the images. I then generate a random number to use as the index of the...
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...
2
by: huwfriedhoff | last post by:
Hi Guys, I have a friend who is developing a dvd store in Visual basic ( It's a WPF application) and stores the data in an XML file. the content of the XML look like this: <DVDInfo> <DVD>...
16
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but...
3
Raventara
by: Raventara | last post by:
Hi all, I have a program which will routinely update the image of a picturebox and resize the picturebox to keep the aspect ratio of the image in tact. The problem I am having is that after about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.