title: How do I retrieve a td value in PHP based on the row of the submit button pressed?
body: <p>I would like to being able to see a td value based on the row that a 'submit' button is in. <img src="https://i.stack.imgur.com/J0xie.jpg" alt="enter image description here"></p>
  
  <p>Here is my html code </p>
  
  <pre><code>&lt;?php foreach($books as $booklist) : ?&gt;
          &lt;tr&gt;
  
              &lt;form action = "." method = "post"&gt;
              &lt;input type="hidden" name="action" value="addtocart" &gt;
              &lt;td&gt;&lt;img height="50" width="50" src=&lt;?php echo "/../../product_manager/uploads/".$booklist['productimage']; ?&gt;&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $booklist['name']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $booklist['version']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $booklist['releaseDate']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $booklist['price']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $booklist['quantity']; ?&gt;&lt;/td&gt;
  
              &lt;td&gt;&lt;input name="submit" type="submit" value = 'Add to cart'/&gt;&lt;td&gt;
              &lt;/form&gt;
  
          &lt;/tr&gt;
          &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>And here is my controller</p>
  
  <pre><code> if($action == 'addtocart'){
  
  echo $booklist['name'];
  }
  </code></pre>
  
  <p>My problem is that it is echoing the last row only. If I echo version, price etc, it only echos the product named test. How can I get it to echo based on the submit button row? Also I'd like to keep it strictly php or html only.</p>