PDA

View Full Version : Ways around handling empty fields on updates.



Multi-Task
March 29th, 2008, 01:32 PM
PHP 5, mysql - I am trying to figure the best way around handling empty fields on updates. So if a field were left empty it wouldnt overwrite existing data stored in that specific row in database.

In my case I am having troubles handling updates where a file upload is part of the form. Does anyone know if turning off the visibility via some DOM practices will make it not register on the POST? Then I could have a button where it could say like change file or something and user could click that and change the visibility to alter it, else it wouldnt be included on the update submit if not.

I was also thinking about wrapping the whole update in a conditional if statement. What are some best practices for handling updates and empty fields and overwriting?

MT

Multi-Task
March 29th, 2008, 01:55 PM
Okay so after testing, DOM will not work. If it is set to hidden still overwrites since empty. What is the best way around this?

Multi-Task
March 29th, 2008, 03:13 PM
Nevermind I figured it out. I first set my file upload with $file = basename($_FILES['file']['name']);

then on UPDATE I break my query such as:
$query = "UPDATE projects SET menu_name = '{$menu_name}' "; if ($file == NULL) {
$query .= " WHERE projectsID = $id ";
} else {
$query .= " , filePath = '{$file}' ";
$query .= " WHERE projectsID = $id ";
}
$result = mysql_query($query);

Multi-Task
March 29th, 2008, 03:14 PM
Now on to handling multiple file uploads....BUAUUUAHHAHAHA BUUHUAHHAHAHAH BUUHAHAHHAHAHAH