title: ajax form request from a while - confuse variable
body: <p>I want to send a form with a button from a while, but I have a problem. If post the button, the form confuse the variable. E.g: i post the button with id 1, and the script get the variable from the last input.
  Code: 
  index: </p>
  
  <pre><code>                &lt;?php 
                  $res = getProdus();
                  foreach($res as $row) { ?&gt;  
                      &lt;form action="addtocart.php" method="POST"&gt;
                          &lt;div class="col-12 col-sm-6 col-md-4 single_gallery_item women wow fadeInUpBig" data-wow-delay="0.2s"&gt;
                              &lt;div class="product-img"&gt;
                                  &lt;img src="img/product-img/product-1.jpg" alt=""&gt;
                                  &lt;div class="product-quicview"&gt;
                                      &lt;a href="#" data-toggle="modal" data-target="#quickview"&gt;&lt;i class="ti-plus"&gt;&lt;/i&gt;&lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="product-description"&gt;
                                  &lt;h4 class="product-price"&gt;$39.90&lt;/h4&gt;
                                  &lt;p&gt;Jeans midi cocktail dress&lt;/p&gt;
                                  &lt;input type="hidden" name="addtcart" value="&lt;?=$row['ID'];?&gt;"&gt;
                                  &lt;button type="submit" class="add-to-cart-btn"&gt;ADD TO CART&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;?php } ?&gt;
  </code></pre>
  
  <p>the ajax request: </p>
  
  <pre><code>$(document).ready(function() {
  $('form').submit(function(event) {
      var formData = {
          'addtcart'        : $('input[name=addtcart]').val()
      };
      $.ajax({
          type        : 'POST', 
          url         : 'addtocart.php',
          data        : formData, 
          dataType    : 'json', 
                      encode          : true
      })
          .done(function(data) {
              console.log(data); 
          });
      event.preventDefault();
  });
  </code></pre>
  
  <p>});
  and the addtocart.php</p>
  
  <pre><code>&lt;?php     
  include("includes/functions.php");
  session_start();
  $errors         = array();      // array to hold validation errors
  $data           = array();      // array to pass back data
  if (empty($_POST['addtcart']))
      $errors['addtcart'] = 'Este necesar produsul id-ului.';
  if ( ! empty($errors)) {
      $data['success'] = false;
      $data['errors']  = $errors;
  } else {
      $ok = AddToCart(filtrare($_POST['addtcart']), getSpec("username", "users", "email", $_SESSION['magazin-user']));
      if($ok == 1) {
          $data['success'] = true;
          $data['message'] = 'Success!';
      } else {
          $data['success'] = false;
          $errors['mysqli'] = "Nu s-a realizat bine query-ul.";
          $data['errors'] = $errors;
      }
  }
  echo json_encode($data);
  </code></pre>
  
  <p>?></p>