Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question a multipart form that does NOT need to be entirely complete?

    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.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    if($upload=="1"){
    $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.

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you GJay, the problem was solved by moving this:

    Code:
    	$qry="insert into $tbl_private2 (custid, author, name, size, content, title, uploadtime) values('$custid','$author','$p_img_name','$p_img_size','$content','$title','$timestamp')";
    $get=mysql_query("$qry",$db);
    to just above the javacript


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •