title: Loop to create multiple button in html and php
body: <p>So basically what I am trying to do is using a loop to display multiple image and create a corresponding button to each image. If I pressed on the corresponding button, it will store the image into another database. </p>
  
  <p>The first part display quite well. However, the second part I can hardly figure out how to determine the corresponding button for each image. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php while($row=mysqli_fetch_array($result)) { ?&gt;
  &lt;div id="item"&gt;
    &lt;?php echo '&lt;img height="200" width="200" src="data:image;base64,'.$row[2]. '"&gt;';?&gt;
    &lt;/br&gt;
    &lt;?php echo $row[ "name"];?&gt;
    &lt;/br&gt;
    &lt;?php echo $row[ "price"];?&gt;
    &lt;/br&gt;
    &lt;?php echo $row[ "description"];?&gt;
    &lt;/br&gt;
   &lt;form&gt;Quantity:
    &lt;input type="text" value="" name="quantity" /&gt;
    &lt;/br&gt;
    &lt;input type="submit" value="add to cart" name="cart" /&gt;
   &lt;/form&gt;
    &lt;?php 
  if (isset($_POST[ "cart"])){ 
  $addtoname=$_SESSION[ 'username']; 
  $addtoprice=$row[ 'price']; 
  $addtodiscount=$row[ 'discount']; 
  $addtoid=$row[ 'id']; 
  $addtoimage=$row[ 'image']; 
  $addtoquantity=$_POST[ 'quantity']; 
  $hostname="localhost" ; 
  $username="root";
  $password="" ; 
  $database="myproject" ; $con=mysqli_connect($hostname,$username,$password,$database) or die(mysqli_error()); 
  $select=mysqli_select_db($con, "myproject")or die( "cannnot select db"); mysqli_query($con,"INSERT INTO cart(username,quantity,price,image,id,discount) VALUES('$addtoname','$addtoquantity','$addtoprice','$addtoimage','$addtoid','$addtodiscount')"); 
  echo "success"; 
  } 
  else{ 
  echo "fail"; 
  }?&gt;
  &lt;/div&gt;
  &lt;?php }//end of while ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It seems like it always go to fail AND never run into isset($_POST[ "cart"]))</p>
  
  <p>Any tips will be much appreciated.</p>
  
  <p>Thank you</p>