title: how to fix double entry and multiple images not insert in PHP MySQL database?
body: <p><em><strong>here is my code when I submit the project, their database has a double entry, I create a primary key autoincrement, and when I upload multiple images in the database their only store the first image, which I use for each function to store multiple images in database</strong></em>**</p>
  <p><strong>Html</strong></p>
  <pre><code>&lt;div class=&quot;card&quot;&gt;
                          &lt;div class=&quot;card-header&quot;&gt;Upload Projects&lt;/div&gt;
                          &lt;div class=&quot;card-body&quot;&gt;
                              &lt;form action=&quot;../partials/project_upload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
                                  &lt;div class=&quot;input-group input-group-sm mb-3&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Catagory Name&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;catName&quot; required&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;input-group input-group-sm mb-3&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Details&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;proDetails&quot; required&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class=&quot;input-group input-group-sm mb-3&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project info&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;proDate&quot;
                                              placeholder=&quot;Date of Project&quot; required&gt;
                                          &lt;input type=&quot;text&quot; class=&quot;form-control mt-3&quot; name=&quot;proLocation&quot;
                                              placeholder=&quot;Project Locaiton&quot; required&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;form-group row&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Frist Image
                                          Select&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;file&quot; class=&quot;form-control&quot; name=&quot;image[]&quot; autofocus&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;form-group row&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Second Image
                                          Select&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;file&quot; class=&quot;form-control&quot; name=&quot;image[]&quot; autofocus&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;form-group row&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Third Image
                                          Select&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;file&quot; class=&quot;form-control&quot; name=&quot;image[]&quot; autofocus&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;form-group row&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Fourth Image
                                          Select&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;file&quot; class=&quot;form-control&quot; name=&quot;image[]&quot; autofocus&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;form-group row&quot;&gt;
                                      &lt;label class=&quot;col-md-4 col-form-label text-md-right&quot;&gt;Project Fifth Image
                                          Select&lt;/label&gt;
                                      &lt;div class=&quot;col-md-6&quot;&gt;
                                          &lt;input type=&quot;file&quot; class=&quot;form-control&quot; name=&quot;image[]&quot; autofocus&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                                  &lt;div class=&quot;col-md-6 offset-md-4&quot;&gt;
                                      &lt;button type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;btn btn-info&quot;&gt;
                                          Upload
                                      &lt;/button&gt;
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
  </code></pre>
  <p><strong>PHP</strong>
  <strong>php upload project code here</strong></p>
  <pre><code>include(&quot;../database/db_connect.php&quot;);
              if (isset($_POST['submit'])) {
                  // Insert the data to the database 
                  $catName=$_POST['catName'];
                  $proDetails=$_POST['proDetails'];
                  $proDate=$_POST['proDate'];
                  $proLocation=$_POST['proLocation'];
                  
                  //all image store in database
                  
                  $extension= array('jpeg','jpg','png',);
                foreach ($_FILES['image']['tmp_name'] as $key =&gt; $value) {
                  $filename=$_FILES['image']['name'][$key];
                  $filename_tmp=$_FILES['image']['tmp_name'][$key];
                  $ext=pathinfo($filename,PATHINFO_EXTENSION);
                  if(in_array($ext,$extension))
                  {
                      if(!file_exists('../assets/projects/'.$filename))
                      {
                      move_uploaded_file($filename_tmp, '../assets/projects/'.$filename);
                      }
                  }
              }
                  
       $sql=&quot;INSERT INTO `projects` (`cat_name`, `pro_details`, `pro_date`, `pro_location`,`pro_image_frist`,`pro_image_second`,`pro_image_third`,`pro_image_fourth`,`pro_image_fifth`) VALUES ('$catName', '$proDetails', '$proDate', '$proLocation','$filename','$filename','$filename','$filename','$filename')&quot;;
                  mysqli_query($conn,$sql); 
                  
                      if (mysqli_query($conn,$sql) == true) {
                          echo &quot;Project Inserted successfully!&quot;;
                          $_SESSION[&quot;access&quot;] = 1;
                      }else{
                          echo &quot;Project Inserted not successfully!&quot;;
                          $_SESSION[&quot;access&quot;] = 1;
                      }
                  header('Location: admin.php');
              }
  </code></pre>
  <p><strong><strong>Database</strong></strong></p>
  <p><em><strong>SQL</strong></em></p>
  <pre><code> --
  -- Table structure for table `projects`
  --
  
  CREATE TABLE `projects` (
    `cat_id` int(11) NOT NULL,
    `cat_name` varchar(15) NOT NULL,
    `pro_details` varchar(1000) NOT NULL,
    `pro_date` varchar(15) NOT NULL,
    `pro_location` varchar(255) NOT NULL,
    `pro_image_frist` varchar(255) NOT NULL,
    `pro_image_second` varchar(255) NOT NULL,
    `pro_image_third` varchar(255) NOT NULL,
    `pro_image_fourth` varchar(255) NOT NULL,
    `pro_image_fifth` varchar(255) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
  --
  -- Dumping data for table `projects`
  --
  
  INSERT INTO `projects` (`cat_id`, `cat_name`, `pro_details`, `pro_date`, `pro_location`, `pro_image_frist`, `pro_image_second`, `pro_image_third`, `pro_image_fourth`, `pro_image_fifth`) VALUES
  (51, 'architecture', 'akbuilder is a great agency for building design', '5/05/2022', 'Sunamganj, ibrahimpur', '35.jpg', '35.jpg', '35.jpg', '35.jpg', '35.jpg'),
  (52, 'architecture', 'akbuilder is a great agency for building design', '5/05/2022', 'Sunamganj, ibrahimpur', '35.jpg', '35.jpg', '35.jpg', '35.jpg', '35.jpg'),
  (53, 'Design', 'hello this is project details', '12/05/2027', 'London', '46.jpg', '46.jpg', '46.jpg', '46.jpg', '46.jpg'),
  (54, 'Design', 'hello this is project details', '12/05/2027', 'London', '46.jpg', '46.jpg', '46.jpg', '46.jpg', '46.jpg'),
  (55, 'architecture', 'akbuilder is a great agency for building design', '12/05/2030', 'Sunamganj, sylhet', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg'),
  (56, 'architecture', 'akbuilder is a great agency for building design', '12/05/2030', 'Sunamganj, sylhet', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg', 'wezkhali mosque14F5c2 - Copy.jpg'),
  (57, 'Akbuilders', 'A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences. Though not required by the syntax of any language, paragraphs are usually an expected part of formal writing, used to organize longer prose', '2020', 'america', '11.jpg', '11.jpg', '11.jpg', '11.jpg', '11.jpg'),
  (58, 'Akbuilders', 'A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences. Though not required by the syntax of any language, paragraphs are usually an expected part of formal writing, used to organize longer prose', '2020', 'america', '11.jpg', '11.jpg', '11.jpg', '11.jpg', '11.jpg'),
  (59, '3D', 'hello this is project details', '12/05/2027', 'London', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg'),
  (60, '3D', 'hello this is project details', '12/05/2027', 'London', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg', 'NZ.jpg'),
  (61, 'projects', 'building design agency ', '2029', 'Sylhet', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg'),
  (62, 'projects', 'building design agency ', '2029', 'Sylhet', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg', 'item1.jpg');
  
  --
  -- Indexes for dumped tables
  --
  
  --
  -- Indexes for table `projects`
  --
  ALTER TABLE `projects`
    ADD PRIMARY KEY (`cat_id`);
  
  --
  -- AUTO_INCREMENT for dumped tables
  --
  
  --
  -- AUTO_INCREMENT for table `projects`
  --
  ALTER TABLE `projects`
    MODIFY `cat_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=63;
  COMMIT;
  </code></pre>