View Full Version : a multipart form that does NOT need to be entirely complete?

05-02-2006, 12:45 AM
Ok, this should be simple.

I have a multipart/form-data form that has text type fields AND a file type field. Everything works great so long as the user enters something in the text fields AND the file field. BUT, if they do NOT select a file to upload, the form does not upload anything to the database. In this case the user may not always want to upload a file, so this is pretty inconvenient.

In case you need to see the code, here is a portion of it: http://publicecology.org/code_example2.txt.

The answer may be in the code itself and I'm just not seeing it... I'm still a novice at this stuff and I couldn't find any answers. Thank you in advance for any suggestions.

05-02-2006, 12:48 AM
$p_img_name = $_FILES["img_upload"]["name"];
$p_img_upload = $_FILES["img_upload"]["tmp_name"];
$p_img_type = $_FILES["img_upload"]["type"];
$p_img_size = $_FILES["img_upload"]["size"];

if($p_img_upload!="" && $p_img_upload!="none"){

if you don't have a file, then the $_FILES array isn't going to contain anything, so that condition will evaulate to false, which means the insert query never gets run.

05-02-2006, 02:52 AM
Thank you GJay, the problem was solved by moving this:

$qry="insert into $tbl_private2 (custid, author, name, size, content, title, uploadtime) values('$custid','$author','$p_img_name','$p_img_size','$content','$title','$timestamp')";

to just above the javacript