title: uploading image in mysql and to a specific directory using php
body: <p>This is my code for upload.php, i want to upload the image in a directory and save its path to mysql database.</p>
  
  <p>The image is successfully uploaded to the directory, but its entry doesn't get inserted into the database.</p>
  
  <ul>
  <li>upload.php</li>
  </ul>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  require("connect.php");
  
  if (isset($_FILES["userfile"]) &amp;&amp; !empty($_FILES["userfile"])) {                                        
  $image = $_FILES['userfile']['tmp_name'];                                   
  $imageName = $_FILES['userfile']['name'];                                   
  $about = $_POST['about'];                                   
  $title = $_POST['title'];                                       
  $place = $_POST['place'];                                       
  $date = $_POST['date'];                                     
  $time = $_POST['time'];                                     
  $link = $_POST['link'];                                 
  $details = $_POST['details'];                                       
  $con = $_POST['con'];                                   
  $email = $_POST['email'];                                       
  $number = $_POST['number'];                                 
  $len = count($image);                                   
  $path = "admin/news/";                                  
  for ($i = 0; $i &lt; $len; $i++) {                                      
      if (isset($imageName[$i]) &amp;&amp; $imageName[$i] !== NULL) {
          if(move_uploaded_file($image[$i], $path.$imageName[$i])) {
               mysqli_query($con,"insert into tblnews (newsid, about,    date_of_event, time, link, event_place, title, details, image, date, contactperson, email, number) values('','$about','$date','$time','$link','$place','$title','$details','$imageName[1]',NOW(),'$con','$email','$number')");
                     echo"&lt;script&gt;alert('The news had been successfuly uploaded.')
                     window.location='index.php?pg=homepage'&lt;/script&gt;";
                                   }
                               }
                 }
  }
  ?&gt;
  </code></pre>
  
  <ul>
  <li>HTML form</li>
  </ul>
  
  <pre><code>&lt;form enctype="multipart/form-data" method="post" action="upload.php"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;About&lt;/th&gt;
              &lt;td&gt;
                  &lt;select name="about"&gt;
                      &lt;option disabled  selected&gt;Select&lt;/option&gt;
                      &lt;option value="Taal"&gt;Taal Volcano&lt;/option&gt;
                      &lt;option value="Malarayat"&gt;Mt. Malarayat Forest Reserve&lt;/option&gt;
                      &lt;option value="vip"&gt;Verde Island Passage&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;td&gt;&lt;input type="text" name="title" required &gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Event's Place&lt;/th&gt;
              &lt;td&gt;&lt;input type="text" name="place" required  &gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Event Date&lt;/th&gt;
              &lt;td&gt;&lt;input type="date" name="date" required&gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Event Time&lt;/th&gt;
              &lt;td&gt;&lt;input type="time" name="time"&gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Image&lt;/th&gt;
              &lt;td&gt;&lt;input name="userfile[]" type="file" multiple='multiple' /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Link on Facebook&lt;/th&gt;
              &lt;td&gt;&lt;input type="text" name="link"&gt;&lt;/input&gt;&lt;/td&gt;
              &lt;td&gt;&lt;span&gt;Go to the facebook page of the event and copy the url and paste it in the textbox.&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Details&lt;/th&gt;
              &lt;td&gt;&lt;textarea name="details" style="height:250px;" &gt;&lt;/textarea&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Contact Person&lt;/th&gt;
              &lt;td&gt;&lt;input type="text" name="con" required  &gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt; 
              &lt;th&gt;Email&lt;/th&gt;
              &lt;td&gt;&lt;input type="email" name="email" required  &gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;Number&lt;/th&gt;
              &lt;td&gt;&lt;input type="text" name="number" &gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;/th&gt;
              &lt;td&gt;&lt;input type="submit" name="add_news" value="Upload"&gt;&lt;/input&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>