PDA

View Full Version : Updating File Inputs



Medyman
01-04-2008, 12:07 AM
Hi all...

I'm constructing a backend in which I have a few file inputs that are uploading files to the server space + saving the filename in MySQL.

Elsewhere in the CMS, I have a set of forms set to update perviously entered sets of data (which include the images).

When I'd like to update other information in the set (i.e. change something besides the images) and save the info back to the MySQL or update it in this case, I lose the entries I had for the image filenames.

The reason is obvoius...b/c I'm updating the data with blank file inputs.

Now, since there is no value attribute for file inputs, how can I make it so that the image data isn't updated in my query unless it has been changed (i.e. it's not blank).

Here's the PHP that I have


$upd = "INSERT INTO $page (id, category, thumbnail, banner, credits, title, author, bio, summary, article, feature, pictured) VALUES ('', '$category', '$thumbnail', '$banner', '$credits', '$title', '$author', '$bio', '$summary', '$article' , '$feature', '$pictured')";

Bascially, thumbnail & banner are filenames from a file inputs.

Jas
01-06-2008, 07:43 PM
If I understand the question right, there are two solutions.
1) on the edit form, load the current values
(this will re-load the value on submit; I like this better b/c the user can see what the value is and make changes, like editing a post on these forums.)
2) on submit, see if the feild is blank.
for example:


1)
<?php
print "<input type='text' name='name' value='".$row['name']."'>";
?>

2)
<?php
if($_POST['name'] != ""){ $query .= " name=\"$name\"";}
?>

Medyman
01-06-2008, 07:47 PM
If I understand the question right, there are two solutions.
1) on the edit form, load the current values
2) on submit, see if the feild is blank.
for example:


1)
<?php
print '<input type='text' name='name' value='".$row['name']."'>';
?>

2)
<?php
if($_POST['name'] != ""){/*process feild*/}
?>



Thanks.
I did something like what I think you're describing in option 2.

Option 1 won't work on file inputs, that was the whole dilemma. It would be a huge security risk if you could pre-fill file input fields.