title: Multiple files uploading in php and mysql with Multiple input fields
body: <p>Please help me.. i have two textbox and and five inputs to upload the files... everything is working good.. the problem is if i skip experience certificate to upload file it will not Insert anything in db.. but when i attach all the documents Resume, Photo, Passport Front, Passport Back and Experience Certificate it is saving and uploading the attachments into db...</p>
  
  <p>please help me how to make Experience Certificate is Not Mandatory..</p>
  
  <p>Please help.. Thanks in Advance..</p>
  
  <pre><code>&lt;form name="companyname" method="POST" action="" enctype="multipart/form-data"&gt;
      First Name: &lt;input name="firstname" type="text"&gt;
      Last Name: &lt;input name="lastname" type="text"&gt;
  
      Resume:* &lt;input type="file" name='resumefile'/&gt;
      Photo:* &lt;input type="file" name='photofile'/&gt;
      Passport Front:* &lt;input type="file" name='passportfront'/&gt;
      Passport Back:* &lt;input type="file" name='passportback'/&gt;
      Experience Certificate: &lt;input type="file" name='experience'/&gt;
  
      &lt;button type="submit" name="misbtn"&gt;Save&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
  require ("config.php"); 
  if(isset($_POST['misbtn']))
  {
  
  $resfile = $_FILES['resumefile'];
  $picfile = $_FILES['photofile'];
  $ppfrnt = $_FILES['passportfront'];
  $ppbck = $_FILES['passportback'];
  $exp = $_FILES['experience'];
  
  if(($resfile['type'] &amp;&amp; $picfile['type'] &amp;&amp; $ppfrnt['type'] &amp;&amp; $ppbck['type'] &amp;&amp; $exp['type'] == 'image/gif')
  || ($resfile['type'] &amp;&amp; $picfile['type'] &amp;&amp; $ppfrnt['type'] &amp;&amp; $ppbck['type'] &amp;&amp; $exp['type'] == 'image/jpeg')
  || ($resfile['type'] &amp;&amp; $picfile['type'] &amp;&amp; $ppfrnt['type'] &amp;&amp; $ppbck['type'] &amp;&amp; $exp['type'] == 'image/png')
  || ($resfile['type'] &amp;&amp; $picfile['type'] &amp;&amp; $ppfrnt['type'] &amp;&amp; $ppbck['type'] &amp;&amp; $exp['type'] == 'application/msword')
  || ($resfile['type'] &amp;&amp; $picfile['type'] &amp;&amp; $ppfrnt['type'] &amp;&amp; $ppbck['type'] &amp;&amp; $exp['type'] == 'application/pdf')
  &amp;&amp; ($resfile['size'] &amp;&amp; $picfile['size'] &amp;&amp; $ppfrnt['size'] &amp;&amp; $ppbck['size'] &amp;&amp; $exp['size'] &lt; 10000000))
  {
      if($resfile['error'] || $picfile['error'] || $ppfrnt['error'] || $ppbck['error'] || $exp['error'] &gt; 0)
      {
          echo "retrun code:" . $resfile['error'] .$picfile['error'] .$ppfrnt['error'] .$ppbck['error'] .$exp['error'];
      }
  
  
  
    // if file exists i am renaming it random number  
      else if(file_exists('upload/'.$resfile['name']) || ('upload/'.$picfile['name']) || ('upload/'.$ppfrnt['name']) || ('upload/'.$ppbck['name']) || ('upload/'.$exp['name']))
      {
  
          $temp = explode(".", $resfile["name"]);
          $temp1 = explode(".", $picfile["name"]);
          $temp2 = explode(".", $ppfrnt["name"]);
          $temp3 = explode(".", $ppbck["name"]);
          $temp4 = explode(".", $exp["name"]);
          $newfilename = round(rand(0000, 9999)) . '.' . end($temp);
          $newfilename1 = round(rand(0000, 9999)) . '.' . end($temp1);
          $newfilename2 = round(rand(0000, 9999)) . '.' . end($temp2);
          $newfilename3 = round(rand(0000, 9999)) . '.' . end($temp3);
          $newfilename4 = round(rand(0000, 9999)) . '.' . end($temp4);
          move_uploaded_file($resfile["tmp_name"], "upload/" . $newfilename);
          move_uploaded_file($picfile["tmp_name"], "upload/" . $newfilename1);
          move_uploaded_file($ppfrnt["tmp_name"], "upload/" . $newfilename2);
          move_uploaded_file($ppbck["tmp_name"], "upload/" . $newfilename3);
          move_uploaded_file($exp["tmp_name"], "upload/" . $newfilename4);
  
          $sql = mysql_query("INSERT INTO maininfosheet(fname, lname, resume, photo, ppfrontattach, ppbckattach, expcertificate)
                              VALUES ('{$_POST['ppnumber']}',
                                      '{$_POST['select_agentname']}',
                                      '{$_POST['firstname']}',
                                      '{$_POST['lastname']}',
                                      '{$newfilename}',
                                      '{$newfilename1}',
                                      '{$newfilename2}',
                                      '{$newfilename3}',
                                      '{$newfilename4}')");
  
          if ($sql)
          {
              echo "successfully insert this record";
          }
  
      }
  
  } else {
  
  
  $sql1 = mysql_query("INSERT INTO maininfosheet(fname, lname)
                      VALUES ('{$_POST['firstname']}',
                              '{$_POST['lastname']}')");
  if ($sql1)
  {
      echo "successfully insert this record";
  }
  
  }
  }
  ?&gt;
  </code></pre>