title: upload all fields with the image file upload optional PHP MySQLI
body: <p>I have searched far and wide and cannot find an answer to my question in terms that I can understand. I am trying to make my code upload all text input fields and if not image is in the file input, then upload all except the image and upload all including the image when an image is present. Below is my working code for when an image is present. All help will be greatly appreciated.</p>
  
  <pre><code>&lt;?php
  session_start();
  error_reporting(E_ALL);
  include_once 'dbconnect.php';
  
  $userID = $_SESSION['usr_id'];
  
  if(!empty($_FILES["uploadedimage"]["tmp_name"])) {
  $eTitle = mysqli_real_escape_string($con, $_POST['etitle']);
  $eDate=mysqli_real_escape_string($con, $_POST['edate']);
  $eDesc=mysqli_real_escape_string($con, $_POST['edesc']);
  $file_tmp = $_FILES['uploadedimage']['tmp_name'];
  $file_ext = strtolower(end(explode('.',$_FILES['uploadedimage']['name'])));
  $date = date("d-m-Y");
  $imagename = $date."-".time().".".$file_ext;
  $target_path = "event_images/".$imagename;  
  $move = move_uploaded_file($file_tmp, $target_path);
  if($move) {
      if($_FILES['uploadedimage']===false){
          $not = "NULL";
      }ELSE{
          $not = $imagename;
      }
  
      $sql =mysqli_query($con, "INSERT INTO `events` (eventID,eventImage,eventTitle,eventDate,eventDescription) values (NULL,'".$not."','".$eTitle."','".$eDate."','".$eDesc."')");
      $db = mysqli_query($sql, $con);
      $msg = "Song has been uploaded successfully";
      header("Location: websiteeditor.events.php");
  }
  else {
      $msg = "Not uploaded because of error #".$_FILES["file"]["error"];
  }
  
  } 
  else {
      $msg = "Failed to Upload&lt;br/&gt;Not uploaded because of error #".$_FILES["file"]["error"];
  }
  
  ?&gt;
  &lt;?=$msg;?&gt;
  </code></pre>