title: Getting image name into the database or is it even needed?
body: <p>This is a two part question although my first delima is how do I get the file name to post to the database, or do I even need it to do that to call the correct image?</p>
  
  <p>Currently, I have have a comment section that is posting and getting properly. I have an image that is moving to the correct directory folder. What I do not have is the file name posting to the database so that I can call on it to pull the correct image out of the directory. Every time I try to add something to post to the database I get an error for my image index being undefined. </p>
  
  <p>Second I would like to be able to call on the image name from the database to pull that image into a thumbnail with the post. I am not entirely sure how to do this yet either. </p>
  
  <p>my question is first off, how do I get the image to post to the database now that I have it moving correctly to the folder?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;?php 
  echo "&lt;form method='POST' enctype='multipart/form-data' action='".setComments($conn)."'&gt;&lt;br&gt;
      &lt;input type='hidden' name='uid' value='Anonymous'&gt;
      &lt;input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'&gt;
  
      Select a file:&lt;br&gt;&lt;input type='file' name='image' id='image'&gt;&lt;br&lt;br&gt;&lt;br&gt;
      Comment:&lt;br&gt; &lt;textarea name='message'&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
      &lt;button type='submit' name='commentSubmit'&gt;Upload&lt;/button&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;/form&gt;";
  
  getComments($conn); 
  ?&gt;
  </code></pre>
  
  <p><strong>Function:</strong></p>
  
  <pre><code>&lt;?php
  function setComments($conn) {
      if (isset ($_POST['commentSubmit'])) {
          $uid = $_POST['uid'];
          $date = $_POST['date'];
          $message = $_POST['message'];
          $file_name = $_FILES['image']['name'];
  
          $sql = "INSERT INTO comments (uid, date, message, images) values ('$uid','$date','$message','$file_name')";
          $result = mysqli_query($conn, $sql);
      }
  }
  
  if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $tmp = explode('.', $file_name);
      $file_ext =  end($tmp);
      $expensions= array("jpeg","jpg","png"."gif");
  
      if(in_array($file_ext,$expensions)=== false){
          $errors[]="extension not allowed, please choose a JPEG, GIF, or PNG file.";
      }
  
      if($file_size &gt; 2097152) {
          $errors[]='File size must be excately 2 MB';
      }
  
          if(empty($errors)==true) {
          move_uploaded_file($file_tmp,"uploads/".$file_name);
          echo "Successfully uploaded file!";
          $sql = "INSERT INTO comments (uid, date, message, images) values ('$uid','$date','$message','$file_name')";
          $result = mysqli_query($conn, $sql);
      }else{
          print_r($errors);
      }
  }
  </code></pre>