title: Want to add value in MySql from form table
body: <p>I have tried to figure out this for a period now but have not yet found a solution. I'm still in learning stage and this is my first project to make a website form scratch.</p>
  
  <p>I have a form where there is a table that the user can fill in information and add new rows.</p>
  
  <p><strong>I wonder how I can save this in MySql.</strong> </p>
  
  <p><em>Hope you can help me with this.</em></p>
  
  <p>Html code looks like this</p>
  
  <pre><code>&lt;div class="table-responsive"&gt;
  &lt;table class="table table-bordered table-hover" id="tab_logic"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;#&lt;/th&gt;
              &lt;th&gt;Varenavn&lt;/th&gt;
              &lt;th&gt;Mengde&lt;/th&gt;
              &lt;th&gt;Enhet&lt;/th&gt;
              &lt;th&gt;Pris&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tfoot&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a id="add_row" class="btn btn-success pull-right"&gt;Add Row&lt;/a&gt;&lt;a id='delete_row' class="pull-right btn btn-danger"&gt;Delete Row&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tfoot&gt;
      &lt;tbody&gt;
         &lt;tr id='addr0'&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name='v_navn0' placeholder='Varenavn' class="form-control" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name='mengde0' placeholder='Mengde' class="form-control" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;select name='enhet0' placeholder='Enhet' class='form-control input-md'&gt;&lt;option&gt;KG&lt;/option&gt;&lt;option&gt;GR&lt;/option&gt;&lt;option&gt;L&lt;/option&lt;option&gt;DL&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name='pris0' placeholder='Pris' class="form-control" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id='addr1'&gt;&lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>And her is my JavaScript code </p>
  
  <pre><code>$(document).ready(function () {
      var i = 1;
      $("#add_row").click(function () {
          $('#addr' + i).html("&lt;td&gt;" + (i + 1) + "&lt;/td&gt;&lt;td&gt;&lt;input name='v_name" + i + "' type='text' placeholder='Varenavn' class='form-control input-md'  /&gt; &lt;/td&gt;&lt;td&gt;&lt;input  name='mengde" + i + "' type='text' placeholder='Mengde'  class='form-control input-md'&gt;&lt;/td&gt;&lt;td&gt;&lt;select name='enhet" + i + "' placeholder='Enhet'  class='form-control input-md'&gt;&lt;option&gt;KG&lt;/option&gt;&lt;option&gt;GR&lt;/option&gt;&lt;option&gt;L&lt;/option&gt;&lt;option&gt;DL&lt;/option&gt;&lt;/select&gt;&lt;/td&lt;/td&gt;&lt;/td&gt;&lt;td&gt;&lt;input name='pris" + i + "' type='text' placeholder='Pris' class='form-control input-md'  /&gt;");
  
          $('#tab_logic').append('&lt;tr id="addr' + (i + 1) + '"&gt;&lt;/tr&gt;');
          i++;
      });
      $("#delete_row").click(function () {
          if (i &gt; 1) {
              $("#addr" + (i - 1)).html('');
              i--;
          }
      });
  
   });
  </code></pre>
  
  <p>And here is my Query </p>
  
  <pre><code>// Create connection
  $conn = new mysqli($servername, $username, $password, $db);
  
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  // definding names
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $navn = ($_POST["navn"]);
  $antall = ($_POST["antall"]);
  $holdbar = ($_POST["holdbar"]);
  $fremgang = ($_POST["fremgang"]);
  $allergen = ($_POST["allergen"]);
  $varenavn = ($_POST["v_navn0"]);
  $mengde = ($_POST["mengde0"]);
  $enhet = ($_POST["enhet0"]);
  $pris = ($_POST["pris0"])     
  }
  
  // Query
  
  $sql = "INSERT INTO oppskrift (opp_navn, antall, holdbarhet, beskrivelse, allergen, varenavn, mengde, enhet, pris)
  VALUES ('$navn', '$antall', '$holdbar', '$fremgang', '$allergen', '$varenavn', '$mengde', '$enhet', '$pris')";
  
  if ($conn-&gt;query($sql) === TRUE) {
  
  // Redirect to login page
                  header("location: /bin/appdata/ny_opp.php");
  
              } else{
                  echo "Something went wrong. Please try again later.";
              }
  
  $conn-&gt;close();
  ?&gt;    
  </code></pre>
  
  <p>and this is my table </p>
  
  <pre><code>CREATE TABLE `oppskrift` (
      `id` INT(11) NOT NULL AUTO_INCREMENT,
      `opp_navn` VARCHAR(255) NULL DEFAULT NULL,
      `antall` VARCHAR(255) NULL DEFAULT NULL,
      `holdbarhet` VARCHAR(50) NULL DEFAULT NULL,
      `beskrivelse` TEXT NULL,
      `allergen` VARCHAR(255) NULL DEFAULT NULL,
      `varenavn` VARCHAR(255) NULL DEFAULT NULL,
      `mengde` VARCHAR(255) NULL DEFAULT NULL,
      `enhet` VARCHAR(255) NULL DEFAULT NULL,
      `pris` VARCHAR(255) NULL DEFAULT NULL,
      PRIMARY KEY (`id`)
  )
  COLLATE='latin1_swedish_ci'
  ENGINE=InnoDB
  AUTO_INCREMENT=16
  ;
  </code></pre>