i am doing an add to cart program.i am listing several products on a single page.but i can only change the quantity of the first product
<p>I am new to php. i am doing an add to cart program.i am listing several products on a single page.but i can only change the quantity of the first product in the list. while the others taking the default value 1.</p>

<p>this program is used for listing multiple products on a single page retrieving from the database.there are different categories and therefore i am taking the cat_id from the URL.</p>

<pre><code>custproduct.php

&lt;?php
session_start();
if (isset($_GET['id']))
{
    // echo"id: ".$_GET['id'];
include ('custdb1.php');
echo "&lt;h2&gt;List of Products:&lt;/h2&gt;";
$sql = "SELECT * FROM `product` WHERE `cat_id`=".$_GET['id'];
$result = $conn-&gt;query($sql);
if ($result-&gt;num_rows &gt; 0) {
     // output data of each row
     while($row = $result-&gt;fetch_assoc()) {
echo "&lt;br&gt; Product ID: ". $row["pro_id"]. " - Product Name: ". $row["pro_name"]. "&lt;br&gt;";
echo "&lt;img src='upload/".$row['pro_img']."'/&gt;";
echo "&lt;br&gt; Price: Rs. ". $row["pro_price"]. " ";
echo "&lt;br&gt;";
 echo "Quantity: &lt;input type='text' name='qty' id='qty' value='1'&gt;";
 echo "&lt;br&gt;";
 echo "&lt;button onclick='addtocart(".$row['pro_id'].")'&gt;Add To Cart&lt;/button&gt;" ;
}

}
}
else {
     echo "0 results";
}

?&gt;

 &lt;script&gt;

function addtocart(id)
{

var qty = document.getElementById('qty').value;
document.write("qty");
window.location ="cart.php?id="+id+"&amp;qty="+qty;

}

&lt;/script&gt;
</code></pre>

<p>this is cart.php page.this page is used to add the products in the cart.the customer will see his cart by clicking the link below "see list"</p>

<pre><code> &lt;?php

session_start();

include('custdb1.php');
//$id = isset($_GET['id']) ? $_GET['id'] : '';
if (isset($_GET['id']))
{
  $id=$_REQUEST["id"];
  $qty=$_REQUEST["qty"];
//echo"qty=".$qty;

$_SESSION['cart'][$id] =  array('id'=&gt; $id,'qty'=&gt; $qty);

$sql = "SELECT `pro_img` FROM `product` WHERE `pro_id`=".$id;
$result = $conn-&gt;query($sql);

if ($result-&gt;num_rows &gt; 0) {
    while($row = $result-&gt;fetch_assoc()) {
        echo "quantity:".$qty.'&lt;br&gt;';
 echo "id:".$id.'&lt;br&gt;';
echo "&lt;img src='upload/".$row['pro_img']."'/&gt;";

     }
}
}
echo "&lt;h4 align='center'&gt;  click here to &lt;a href='shoppingcart.php'&gt;see list&lt;/a&gt; &lt;/h4&gt;";
echo "&lt;h4 align='center'&gt;  click here to &lt;a href='custprofile.php'&gt;Continue Shopping&lt;/a&gt; &lt;/h4&gt;";
?&gt;
</code></pre>

<p>this is shopping cart.php.this page shows the added products in the cart...i.e the customer can see his cart.</p>

<pre><code>&lt;?php

session_start();
include('custdb1.php');
echo "&lt;pre&gt;";

$value=$_SESSION['cart'];
//print_r($value);
foreach ( $value as $key=&gt; $final_val ){

              $cat_id = $key;
              $pro_id = $final_val['id'];
              $qty = $final_val['qty'];
            echo"product id:".$pro_id;
            echo"quantity:".$qty;
              $sql = "SELECT * FROM `product` WHERE `pro_id`=".$pro_id;

$result = $conn-&gt;query($sql);

if ($result-&gt;num_rows &gt; 0) {
     // output data of each row
     while($row = $result-&gt;fetch_assoc()) {
        echo "&lt;br&gt; Product ID: ". $row["pro_id"]. " - Product Name: ". $row["pro_name"]. "&lt;br&gt;";
        echo "&lt;img src='upload/".$row['pro_img']."'/&gt;";
       // echo "&lt;button onclick='update(".$row['pro_id'].")'&gt;update&lt;/button&gt;" ;
      // echo "&lt;h4 align='left'&gt;&lt;a href='update.php'&gt;update cart&lt;/a&gt; &lt;/h4&gt;";
}

}
else {
     echo "0 results";
}
}

echo "&lt;h4 align='center'&gt;  click here to &lt;a href='custprofile.php'&gt;Continue Shopping&lt;/a&gt; &lt;/h4&gt;";
?&gt;
</code></pre>