Can't get the value from other textfield except the first one
<p>I use the code from phpwebcommerce's shopping cart tutorial, and I am trying to add a text field for user to insert quantity. Since there are different number of choices for a single product, so I use the while statement to query the sub-items and put a text field plus a add button beside each of them. But it only takes the quantity for the first item, and not the rest. If I insert a quantity for the first item, and click on "add" on any of other items, it will still store the first in my cart, which it should not... I am stuck... can someone help me out?</p>

<pre><code>&lt;?php
function displayprodDetail($pdId)
{
    $query = mysql_query("SELECT * FROM product_image WHERE p_id ='$pdId'");
    WHILE($datarows = mysql_fetch_array($query))
    {
        $p_num = $datarows['p_number'];
        echo '&lt;h1&gt;&lt;span&gt;'.$p_num.' -- $'.$datarows['price'].'&lt;/span&gt;&lt;/h1&gt;';
        echo '&lt;div id="prodPic"&gt;&lt;a href ="'.$datarows['image']. '" rel="ibox"    title="'.$p_num.'"&gt;&lt;img src ="'.$datarows['image'].'"/&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;';
        echo '&lt;div id="items"&gt;';
        $sql = mysql_query("SELECT * FROM items WHERE item_number LIKE '$p_num/%' ORDER BY item_number ASC");
        $numProduct = dbNumRows($sql);
        if($numProduct &gt; 1)
        {
            echo '&lt;table border="0" cellspacing="0"&gt;';
            WHILE($data = mysql_fetch_array($sql))
            {
                $itemId = $data['item_id'];
                $p_num = $data['item_number']; 
                echo '&lt;tr&gt;';
                echo '&lt;td&gt;&lt;INPUT TYPE="HIDDEN" NAME="'.$itemId.'" VALUE="'.$itemId.'"&gt;'.$p_num.'&lt;/td&gt;';
                echo '&lt;td&gt;&amp;nbsp;&amp;nbsp;Qty: &lt;input type="number" name="qty" id="qty" style="width:30px"&gt;&lt;/td&gt;';
                $cart_url = "cart.php?action=add&amp;i=$itemId&amp;qty=";
                ?&gt;
                &lt;td&gt;&lt;input type="Submit" name="Submit" value="Add" onClick="window.location.href='&lt;?php echo $cart_url; ?&gt;' +document.getElementById('qty').value;" &gt;&lt;/td&gt;
                &lt;?php
                echo '&lt;/tr&gt;';
            }
            echo '&lt;/table&gt;';
        }
        else
        {
            echo 'Items are currently not available.&lt;br&gt;Contact us for more detail.';
        }

        echo '&lt;/div&gt;';
    }
}
?&gt;
</code></pre>

<p>Here is the add to cart function:</p>

<pre><code>function addToCart()
{
    // make sure the product id exist
    if (isset($_GET['i']) &amp;&amp; (int)$_GET['i'] &gt; 0) 
    {
        $itemId = (int)$_GET['i'];
    } 
    else 
    {
        header('Location: home.php');
    }
    if (isset($_GET['qty']) &amp;&amp; (int)$_GET['qty'] &gt; 0) 
    {
        $qty = (int)$_GET['qty'];
    } 
    // current session id
    $sid = session_id();

    // check if the product is already
    // in cart table for this session
    $sql = mysql_query("SELECT item_id FROM cart_table WHERE item_id = $itemId AND ct_session_id = '$sid'");

    if (dbNumRows($sql) == 0) 
    {
        // put the product in cart table
        $sql = mysql_query("INSERT INTO cart_table (item_id, ct_qty, ct_session_id, ct_date) VALUES ($itemId, $qty, '$sid', now())");
    } 
    else 
    {
        // update product quantity in cart table
        $sql = mysql_query("UPDATE cart_table SET ct_qty = ct_qty + $qty WHERE ct_session_id = '$sid' AND item_id = $itemId");                  
    }   

    // an extra job for us here is to remove abandoned carts.
    // right now the best option is to call this function here
    deleteAbandonedCart();

    header('Location: ' . $_SESSION['shop_return_url']);                
}
</code></pre>
