title: php - insert multiple rows into mysql from form loop
body: <p>So I am displaying multiple html forms on a page -  works great because I am just using a simple loop to display it 80 times but the issue I am facing is I would like to take all 80 forms and submit them into multiple rows in my database. It's only submitting the last form (which is 80)</p>
  
  <p>If anyone can help me find the issue... I would really appreciate it! I've done some searching before submitting this question but I can't seem to find a answer. </p>
  
  <p><br>
  <strong>Here is what my table looks like:</strong><br><br>
  <a href="https://i.stack.imgur.com/K6c5P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K6c5P.png" alt="enter image description here"></a></p>
  
  <p><strong>Here is my form builder</strong></p>
  
  <pre><code>&lt;?php 
  // Counts the number of forms
  $counter = 1;
  
  echo '&lt;form action="insert.php" method="post"&gt;';
  
  
  // Loop through forms
  for ($i = 1; $i &lt; 81; $i++) {
  
  $username = 'admin';
  $title = 'test';
  $name = 'a';
  $image_src = '&lt;img src="image/'.$i.'.jpg"&gt;';
  $transition = 'fade';
  $group_name  = '0';
  
  
  echo '&lt;hr&gt;' . '('. $counter .')'. '&lt;br&gt;';
  
  echo "
  &lt;label&gt;Username:&lt;/label&gt;
  &lt;input type='text' name='username' id=' required='required' value='".$username."'/&gt;
  
  &lt;br /&gt;&lt;br /&gt;
  
  &lt;label&gt;Title:&lt;/label&gt;
  &lt;input type='text' name='title' id=' required='required' value='".$title."'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  
  &lt;label&gt;Name:&lt;/label&gt;
  &lt;input type='text' name='name' id=' required='required' value='".$name."'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  
  &lt;label&gt;Content:&lt;/label&gt;
  &lt;input type='text' name='content' id=' required='required' value='".$image_src."'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  
  &lt;label&gt;Image:&lt;/label&gt;
  &lt;input type='text' name='image' id=' required='required' value='images/".$i.".jpg'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  
  &lt;label&gt;CSS Animate:&lt;/label&gt;
  &lt;input type='text' name='cssanimate' id=' required='required' value='".$transition."'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  
  &lt;label&gt;Group Name:&lt;/label&gt;
  &lt;input type='text' name='group_name' id=' value='0'/&gt;
  
  &lt;br/&gt;&lt;br /&gt;
  ";
  
  $counter++;
  
  }
  
  echo '&lt;input type="submit" value="Submit" name="submit"/&gt;';
  echo '&lt;/form&gt;';
  
  ?&gt;
  </code></pre>
  
  <p><hr>
  <strong>Here is my php code: (insert.php)</strong></p>
  
  <pre><code>&lt;?php
  
  $con=mysqli_connect("localhost","admin","password","database_name");
  // Check connection
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  
  $sql="INSERT INTO table_name (username, title, name, content, image, cssanimate, group_name, group_sort) VALUES ('".$_POST["username"]."', '".$_POST["title"]."', '".$_POST["name"]."', '".$_POST["content"]."', '".$_POST["image"]."', '".$_POST["cssanimate"]."', '".$_POST["group_name"]."', '".$_POST["group_sort"]."') ";
  
  if (!mysqli_query($con,$sql))
    {
    die('Error: ' . mysqli_error($con));
    } echo "Added!";
  
  mysqli_close($con);
  
  
  ?&gt;
  </code></pre>