title: If else statements with file upload
body: <p>I have a simple file uploader on my index.php page which it gets posted to my addnew.php page along with 2 other input fields like this below:</p>
  
  <pre><code>&lt;form action="addnew.php" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="text" name="title" placeholder="Title"&gt;
  &lt;input type="text" name="location" placeholder="location"&gt;
  &lt;input type="file" name="file"&gt;
  &lt;input type="submit" value="add"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>my question is that when it sends to the file upload, it sends a generateRandomString function to replace the original file name, so if the form field is empty, it still sends a string of 10 random characters to my database. My question is that how can I set a if/else statement so that it does not send the random characters to my database if the upload field is empty. Here's the idea that I have, but it's obviously not working..</p>
  
  <pre><code>if (!empty($_FILES['file'])=="") {
      $sql="INSERT INTO tabletry (title, location)
            VALUES ('".addslashes($title)."', '".addslashes($location)."')";
  } else {
      $ext = pathinfo($_FILES['file']['name'])['extension'];
      $nFn = generateRandomString(). ".$ext";
      move_uploaded_file($_FILES['file']['tmp_name'],"pictures/".$nFn);
  
      function generateRandomString($legnth = 10) {
          return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"),0, $legnth);
      }
  
      $sql="INSERT INTO tabletry (title, location, mainimage) 
            VALUES ('".addslashes($title)."', '".addslashes($location)."', '{$nFn}')";  
  }
  </code></pre>
  
  <p>any help would be amazing..</p>