Re: Image Edit Uploading Problem.

From: Date: Sat, 22 Sep 2001 02:17:56 +0000
Subject: Re: Image Edit Uploading Problem.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68259@lists.php.net to get a copy of this message
The trick you are missing is this: You can use an if/else to build your *SQL* piece-meal as well: $SQL = "update $table_name set "; if ($userfile_th != 'none'){ $SQL .= " thumbnail='$userfile_th_name', "; } if ($userfile_full != 'none'){ $SQL .= " full_size='$userfile_full_name', "; } $SQL .= " title='$title', caption='$caption' WHERE ID=\"$ID\""; Now, no matter which they uploaded, your SQL only updates the fields that should change, and leaves the others alone. You may also want to re-structure this so that you do the copy() *FIRST* and only update if that succeeds, so you never have your db out-of-sync with reality in the event of copy() failure, and use that new-fangled uploaded_file_copy() function or whatever it is. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: Michael O'Neal <mike@thinkmango.com> Newsgroups: php.general To: "Php-General@Lists. Php. Net" <php-general@lists.php.net> Sent: Monday, September 17, 2001 1:05 PM Subject: Image Edit Uploading Problem. > Hi, > > I'm creating a PHP/MySQL photo gallery app and I'm having problem with my > "edit" page. I want the user to be able to change any of the fields in the > record. In this case there are two text fields, and two "file" fields where > they can browse to replace the images that are currently in the database. > The "file" fields send a variable of "none" if the user doesn't change > it. > So, what I've done is created an if/else statement that says if these fields > DON'T = "none", then do the SQL. However, I didn't account for the user > just updating ONE of the image fields. Below is what I have so far: > > > > > <?php > > if (($userfile_th) && ($userfile_full) && ($userfile_th && > $userfile_full != > "none")) { > > $db_name = "wonderland"; > $table_name = "photo"; > $connection = @mysql_connect("$db_loc","$db_user","$db_pass") or > die("Couldn't Connect."); > $db = @mysql_select_db($db_name, $connection) or die("Couldn't select > database."); > > > > $sql ="UPDATE $table_name set > title='$title',caption='$caption',thumbnail='$userfile_th_name',full_size='$ > userfile_full_name' WHERE ID=\"$ID\""; > $result = @mysql_query($sql, $connection) or die("Couldn't execute query."); > > copy($userfile_th, > "/Users/emptyo/Sites/wonderland/images/gallery/thumbnail/$userfile_th_name") > ; > copy($userfile_full, > "/Users/emptyo/Sites/wonderland/images/gallery/full_size/$userfile_full_name > "); > > include("edit_photo_upd_suc.html"); > > } > > else { > > > $db_name = "wonderland"; > $table_name = "photo"; > $connection = @mysql_connect("$db_loc","$db_user","$db_pass") or > die("Couldn't Connect."); > $db = @mysql_select_db($db_name, $connection) or die("Couldn't select > database."); > > > > $sql ="UPDATE $table_name set title='$title',caption='$caption' WHERE > ID=\"$ID\""; > $result = @mysql_query($sql, $connection) or die("Couldn't execute query."); > > > > > include("edit_photo_upd_ok.php"); > > > > > } > > ?> > > > So, my question is, do I need to do a separate if/else statement for every > combination of what the user might want to change (Two text fields, and one > image, or both images and no text fields, or 1 text field and 1 image, > etc..) or is there a catch-all that might be able to do this for me? > > I'm a pretty new PHP'er, so forgive me if this is an obvious question, or > there is a better way to do this. > > Please respond directly to mike@thinkmango.com as I am on the digest. > > TIA, > > > mto > > -- > > Michael O'Neal > Web Producer/ Autocrosser > ST 28 '89 Civic Si > --------------------- > M A N G O > B O U L D E R > --------------------- > http://www.thinkmango.com > e- mike@thinkmango.com > p- 303.442.1821 > f- 303.938.8507 >

« previous php.general (#68259) next »