title: how do i submit a form without errors if a file field is empty in php?
body: <p>I have a page that inserts records into a table. what i am having a little bit of trouble with, is if the user decides that he does not want to include a picture, how do i submit the form without errors. Or is there a way to set the file field to select a default image from a folder and set it as the file entry if there is no selection from the user?</p>
  
  <p>I have been able to solve the problem. Below is the code:</p>
  
  <pre><code>$editFormAction = $_SERVER['PHP_SELF'];
  if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ($_FILES['photo'] &amp;&amp; $_FILES['photo']['error'] == 0) {
  
  $set['photo'] = "'" . $pix . "'";
  
  $image = @getimagesize($_FILES['photo']['tmp_name']);
  $size = ($_FILES["photo"]["size"]&lt;= 512000);
  if($image &amp;&amp; $size = TRUE)
  $pix= $_FILES['photo']['name'];
  
  $kaboom = explode(".", $pix);
  $pixExt = end($kaboom);
  $photo= rand()."_".time().".".$pixExt; 
  $tmpName = $_FILES['photo']['tmp_name']; 
  
  $target = "../events/";
  
  $target = $target . $photo; 
  }
  move_uploaded_file($tmpName, $target); 
  
  
      if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "pd")) {
        $insertSQL = sprintf("INSERT INTO events (title, detail, `date`, photo) VALUES (%s, %s, %s, '$photo')",
                             GetSQLValueString($_POST['title'], "text"),
                             GetSQLValueString($_POST['detail'], "text"),
                             GetSQLValueString($_POST['date'], "text"));
  
        mysql_select_db($database_connMain, $connMain);
        $Result1 = mysql_query($insertSQL, $connMain) or die(mysql_error());
  
        $insertGoTo = "confirm.php?user=" . $row_rsadmin['aID'] . "";
        if (isset($_SERVER['QUERY_STRING'])) {
          $insertGoTo .= (strpos($insertGoTo, '?')) ? "&amp;" : "?";
          $insertGoTo .= $_SERVER['QUERY_STRING'];
        }
        header(sprintf("Location: %s", $insertGoTo));
      }
  </code></pre>