title: Get specific value from a PHP submit button placed in loop
body: <p>Here is my Html and PHP code, I've commented all the details, I want specific data depending on which button is clicked by the user, but the button is printed in a loop, whenever I try to access it gives the last updated data in submit button. because every time while loop executes, it is obvious to change values of <strong>$row</strong> variable, how can I manage to get appropriate values according to which submit button is clicked.
  can it be done using an array?
  any piece of code that can help?</p>
  <pre><code>&lt;?php
  require_once '../includes/header.php';
  require_once '../includes/connection.php';
  
  //i got data from table
  $sql=&quot;select * from shoes&quot;;
  $result = $con-&gt;query($sql);
  ?&gt;
  
  &lt;html&gt;
  &lt;main role=&quot;main&quot;&gt;
  &lt;section class=&quot;sec-intro&quot; role=&quot;section&quot;&gt;
        &lt;h1&gt;Products&lt;/h1&gt;
  &lt;/section&gt;
  
      
      
  &lt;section class=&quot;sec-boxes&quot; role=&quot;section&quot;&gt;
  
  
  &lt;!-- I placed a PHP loop here --&gt;
  &lt;?php
  while ($row = $result-&gt;fetch_assoc()) {
  ?&gt;
  
  &lt;article class=&quot;box&quot;&gt;
  &lt;!-- Printing Data of Shoe --&gt; 
  
      &lt;img src=&quot;&lt;?= $row['image'] ?&gt;&quot; width=&quot;250px&quot; height=&quot;300px&quot;&gt;
      &lt;h1&gt; &lt;?= $row['shoe_name'] ?&gt;&lt;/h1&gt;
  
      &lt;?php
      //cutting the long strings into short becasue shoe description was long
              $des = $row['shoe_description'];
              if (strlen($des)&gt;70)
              {
                    // truncate string
                      $stringCut = substr($des, 0, 90);
                      $endPoint = strrpos($stringCut, ' ');
                      $des = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
                      $des .= '... &lt;a class= &quot;link&quot; href=&quot;search.php&quot;&gt;Read More&lt;/a&gt;';
              }
      ?&gt;
      &lt;p&gt; &lt;?= $des ?&gt; &lt;/p&gt;
      
      &lt;!------------------------------------------
      ----------------------------------------
      ---------- PROBLEM IS HERE -------------------
      ------------------------------------------
      -------------------------------------&gt;
      
      &lt;input class=&quot;button&quot; type=&quot;submit&quot; name = &quot;submit&quot; value=&quot;Add to Cart&quot; width= &quot;150px&quot;; /&gt;
      
      &lt;!-- THIS ADD TO CART BUTTON IS INSIDE LOOP
           AND I WANT SHOE_ID AND SHOE_NAME OF THAT
           SPECIFIC BUTTON OF SHOE SPECIFIC SHOE --&gt;
  &lt;/article&gt;
  
  &lt;?php } ?&gt;
  &lt;!-- PHP LOOP ENDED HERE --&gt;
  
      
      &lt;?php
      if(isset($_POST['submit']))
      {
          $id = $_POST['shoe_id'];        //here i need the shoe id of that specific shoe.
      }
      
      ?&gt;
        
  &lt;/section&gt;
  
  &lt;!-- THIS WILL REMAIN SAME THROUGHOUT THE WEBSITE --&gt;
  
  &lt;/main&gt;
  
  &lt;?php
      require_once '../includes/footer.php';
  ?&gt;
  
  
  
  &lt;/html&gt;
  </code></pre>
  <p>The image of the web page is attached for clarity:
  <a href="https://i.stack.imgur.com/iRv6Z.jpg" rel="nofollow noreferrer">page display</a></p>
  <p>EDIT/UPDATE: The <code>if(isset($_POST['submit']))</code> isn't working as well ??</p>