title: Insert multiple images into database - PHP PDO
body: <p>I need a little help or advice. I create advanced storing form in PHP PDO. Form must have upload post image ( header image ) and gallery images ( multi image store into database in same database ). I have done with store single image into database, but im stuck with multi store images into same database. I will put my code here.</p>
  
  <pre><code>&lt;?php require('includes/config.php'); 
      //if not logged in redirect to login page
      if(!$user-&gt;is_logged_in()){ header('Location: index.php'); } 
      // Upload posted information
      include('core/connection.php');
      include('functions/main.php');
      if($_POST){
          $nameproduct = $_POST['nameProduct'];
          $categoryproduct = $_POST['categoryProduct'];
          $keywordproduct = $_POST['keywordProduct'];
          $addressproduct = $_POST['addressProduct'];
          $latproduct = $_POST['latProduct'];
          $lonproduct = $_POST['lonProduct'];
          $locationproduct = $_POST['locationProduct'];
          $telproduct = $_POST['telProduct'];
          $emailproduct = $_POST['emailProduct'];
          $siteproduct = $_POST['siteProduct'];
          $pdate = date("Y-m-d H:i:s");
          if(empty($nameproduct) or empty($keywordproduct)){
              $errors = '&lt;div class="error2"&gt;&lt;p&gt; All fields are required. Please try again&lt;/p&gt;&lt;/div&gt;';
          }else{
              if (isset($_FILES['post_image'])===true) {       
                  if (empty($_FILES['post_image']['name']) ===true) {
                      $errors = '&lt;div class="error2"&gt;Please Choose a Post Image&lt;/div&gt;';
                   }else {   
                       $allowed = array('jpg','jpeg','gif','png'); 
                       $file_name = $_FILES['post_image']['name']; 
                       $file_extn = strtolower(end(explode('.', $file_name)));
                       $file_temp = $_FILES['post_image']['tmp_name'];
                       if (in_array($file_extn, $allowed)===true) {
                          $file_parh = 'images/' . substr(md5(time()), 0, 10).'.'.$file_extn;
                          move_uploaded_file($file_temp, $file_parh);                         
                          $query = $pdo-&gt;prepare("INSERT INTO `go-wp`.`products` (`post_id`, `nameProduct`, `categoryProduct`, `keywordProduct`, `addressProduct`, `latProduct`, `lonProduct`, `locationProduct`, `telProduct`, `emailProduct`, `siteProduct`, `post_date`, `post_image`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                          $query-&gt;bindValue(1, $nameproduct); 
                          $query-&gt;bindValue(2, $categoryproduct); 
                          $query-&gt;bindValue(3, $keywordproduct);
                          $query-&gt;bindValue(4, $addressproduct);
                          $query-&gt;bindValue(5, $latproduct);
                          $query-&gt;bindValue(6, $lonproduct);
                          $query-&gt;bindValue(7, $locationproduct);
                          $query-&gt;bindValue(8, $telproduct);
                          $query-&gt;bindValue(9, $emailproduct);
                          $query-&gt;bindValue(10, $siteproduct);
                          $query-&gt;bindValue(11, $pdate);  
                          $query-&gt;bindValue(12, $file_parh);
                          $query-&gt;execute();  
                          header('Location: view_product.php');   
                      }
                  }
              }
          }   
      }
  ?&gt;
  </code></pre>
  
  <p>Code above present store single image into database ( works nice ). But when i add into HTML code next code ( below ) i have problems. What to write, how to create nice script. I open form html <code>&lt;form action="" method="post" enctype="multipart/form-data"&gt;</code></p>
  
  <pre><code>&lt;div class="col-md-4"&gt;
      &lt;div class="act-widget fl-wrap"&gt;
          &lt;div class="profile-edit-header fl-wrap"&gt;
              &lt;h4&gt;Gallery product&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="add-list-media-wrap fuzone"&gt;
              &lt;div class="fu-text"&gt;
                   &lt;span&gt;&lt;i class="fa fa-picture-o"&gt;&lt;/i&gt; Add multiple images&lt;/span&gt;
              &lt;/div&gt;
              &lt;input class="input-group" class="upload" type="file" name="post_image" id="imgInput" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Full HTML code looks like this:</p>
  
  <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt;
      &lt;div class="profile-edit-container add-list-container"&gt;
          &lt;div class="profile-edit-header fl-wrap"&gt;
              &lt;h4&gt;Information product&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="custom-form"&gt;
              &lt;label&gt;Product name&lt;i class="fa fa-briefcase"&gt;&lt;/i&gt;&lt;/label&gt;
              &lt;input type="text" name="nameProduct" placeholder="Product name" value=""/&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;label&gt;Category&lt;/label&gt;
                      &lt;select name="categoryProduct" data-placeholder="Select product category:" class="chosen-select"&gt;
                          &lt;option value="Choose category" selected&gt;Choose category:&lt;/option&gt;
                          &lt;option value="Category1"&gt;Category1&lt;/option&gt;
                          &lt;option value="Category2"&gt;Category2&lt;/option&gt;
                          &lt;option value="Category3"&gt;Category3&lt;/option&gt;
                          &lt;option value="Category4"&gt;Category4&lt;/option&gt;
                      &lt;/select&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;label&gt;Keywords&lt;i class="fa fa-key"&gt;&lt;/i&gt;&lt;/label&gt;
                      &lt;input type="text" name="keywordProduct" placeholder="Max 5 keywords" value=""/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="profile-edit-container add-list-container"&gt;
          &lt;div class="profile-edit-header fl-wrap"&gt;
              &lt;h4&gt;Product location&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="custom-form"&gt;
              &lt;label&gt;Address&lt;i class="fa fa-map-marker"&gt;&lt;/i&gt;&lt;/label&gt;
              &lt;input type="text" name="addressProduct" placeholder="Address" value=""/&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;label&gt;Latitude:&lt;i class="fa fa-map-marker"&gt;&lt;/i&gt;&lt;/label&gt;
                      &lt;input type="text" name="latProduct" id="lat" placeholder="Latitude" value=""/&gt;                                                    
                  &lt;/div&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;label&gt;Longitude:&lt;i class="fa fa-map-marker"&gt;&lt;/i&gt;&lt;/label&gt;
                      &lt;input type="text" name="lonProduct" id="long" placeholder="Longitude" value=""/&gt;                                                    
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="map-container"&gt;
                  &lt;div id="singleMap" data-latitude="40.7427837" data-longitude="-73.11445617675781"&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;label&gt;Location&lt;/label&gt;
              &lt;select name="locationProduct" data-placeholder="Location" class="chosen-select" &gt;
                  &lt;option value="Choose location" selected&gt;Choose location:&lt;/option&gt;
                  &lt;option value="Location1"&gt;Location1&lt;/option&gt;
                  &lt;option value="Location2"&gt;Location2&lt;/option&gt;
                  &lt;option value="Location3"&gt;Location3&lt;/option&gt;
                  &lt;option value="Location4"&gt;Location4&lt;/option&gt;
                  &lt;option value="Location5"&gt;Location5&lt;/option&gt;
                  &lt;option value="Location6"&gt;Location6&lt;/option&gt;
              &lt;/select&gt;
              &lt;label&gt;Phone&lt;i class="fa fa-phone"&gt;&lt;/i&gt;&lt;/label&gt;
              &lt;input type="text" name="telProduct" placeholder="Phone" value=""/&gt;
              &lt;label&gt;Email&lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;&lt;/label&gt;
              &lt;input type="text" name="emailProduct" placeholder="Email" value=""/&gt;
              &lt;label&gt;Site&lt;i class="fa fa-globe"&gt;&lt;/i&gt;&lt;/label&gt;
              &lt;input type="text" name="siteProduct" placeholder="Site" value=""/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-md-4"&gt;
          &lt;div class="act-widget fl-wrap"&gt;
              &lt;div class="profile-edit-header fl-wrap"&gt;
                  &lt;h4&gt;Header image&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="add-list-media-wrap fuzone"&gt;
                  &lt;div class="fu-text"&gt;
                      &lt;span&gt;&lt;i class="fa fa-picture-o"&gt;&lt;/i&gt; Add header image&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;input class="input-group" class="upload" type="file" name="post_image" id="imgInput" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-md-4"&gt;
          &lt;div class="act-widget fl-wrap"&gt;
              &lt;div class="profile-edit-header fl-wrap"&gt;
                  &lt;h4&gt;Gallery image&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="add-list-media-wrap fuzone"&gt;
                  &lt;div class="fu-text"&gt;
                      &lt;span&gt;&lt;i class="fa fa-picture-o"&gt;&lt;/i&gt; Add gallery images&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;input class="input-group" class="upload" type="file" name="post_image" id="imgInput" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="custom-form"&gt;
          &lt;button name="submit" class="btn big-btn color-bg flat-btn"&gt;Add product&lt;i class="fa fa-angle-right"&gt;&lt;/i&gt;&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How to generate code for storing multy images into database with this code. Thanks all</p>