Append new html table row after submit
<p>I'm working on some php files that retieve only one record from a database and i have to add the products to get total amount. The problem is to add new item one after another, when I add I only see one row and when I click the add button the items get replaced in the same row</p>

<p>here are the codes</p>

<p><em>file1</em></p>

<pre><code>&lt;?php
session_start();
$link = mysql_connect("server","root","password");
if (!$link) {
   die("Could not connect to Server");
}
mysql_select_db("dbname",$link);

$pid = $_REQUEST['product_id'];

$query_string = "select * from products where product_id=$pid";
$result = mysql_query($query_string);

$num_rows = mysql_num_rows($result);
if ($num_rows &gt; 0 ) {
    print "&lt;form action='checkout.php' name='cart' target='Bottom Right Frame' method='post' onSubmit='return check_field()'&gt;";
    print "&lt;table&gt;";
    print "&lt;tr&gt;";
    print "&lt;th&gt;Product ID&lt;/th&gt;";
    print "&lt;th&gt;Product Name&lt;/th&gt;";
    print "&lt;th&gt;Unit Price&lt;/th&gt;";
    print "&lt;th&gt;Unit Quantity&lt;/th&gt;";
    print "&lt;th&gt;In Stock&lt;/th&gt;";
    print "&lt;th&gt;QTY&lt;/th&gt;";
    print "&lt;th&gt;Add Item&lt;/th&gt;";
    print "&lt;/tr&gt;";
    while ( $a_row = mysql_fetch_assoc($result) ) {
        print "&lt;tr&gt;\n";
        print "&lt;td&gt;".$a_row['product_id']."&lt;/td&gt;";
        print "&lt;td&gt;".$a_row['product_name']."&lt;/td&gt;";
        print "&lt;td&gt;".$a_row['unit_price']."&lt;/td&gt;";
        print "&lt;td&gt;".$a_row['unit_quantity']."&lt;/td&gt;";
        print "&lt;td&gt;".$a_row['in_stock']."&lt;/td&gt;";
        print "&lt;td&gt;&lt;input type='text' id='quantity' name='qty' size='4' maxlength='4' /&gt;&lt;/td&gt;";
        print "&lt;td&gt;&lt;input type='submit' id='add' name='add_qty' value='add' /&gt;&lt;/td&gt;";
        print "&lt;/tr&gt;";
        $_SESSION['product_id'] = $a_row["product_id"];
        $_SESSION['product_name'] = $a_row["product_name"];
        $_SESSION['unit_price'] = $a_row["unit_price"];
        $_SESSION['unit_quantity'] = $a_row["unit_quantity"];
        $_SESSION['in_stock'] = $a_row["in_stock"];
    }
    print "&lt;/table&gt;&lt;/form&gt;";
}
mysql_close($link);
?&gt;'
</code></pre>

<p><em>file2</em></p>

<pre><code>&lt;?php
session_start();
$addrow = 1;
$amount = $_REQUEST['qty'] * $_SESSION['unit_price'];
print "&lt;table&gt;";
print "&lt;tr&gt;";
print "&lt;th&gt;Product ID&lt;/th&gt;";
print "&lt;th&gt;Product Name&lt;/th&gt;";
print "&lt;th&gt;Unit Quantity&lt;/th&gt;";
print "&lt;th&gt;Total Quantity&lt;/th&gt;";
print "&lt;th&gt;Total Price&lt;/th&gt;";
print "&lt;/tr&gt;";
for($counter = 0;$counter&lt;$addrow;$counter++){
    print "&lt;tr&gt;";
    print "&lt;td&gt;".$_SESSION['product_id']."&lt;/td&gt;";
    print "&lt;td&gt;".$_SESSION['product_name']."&lt;/td&gt;";
    print "&lt;td&gt;".$_SESSION['unit_quantity']."&lt;/td&gt;";
    print "&lt;td&gt;".$_REQUEST['qty']."&lt;/td&gt;";
    print "&lt;td&gt;$".$amount."&lt;/td&gt;";
    print "&lt;/tr&gt;";
    }
print "&lt;tr&gt;";
print "&lt;th colspan='3' rowspan='1'&gt;&lt;div class='checkout'&gt;&lt;form action='complete_checkout.php' target='Top Right Frame' method='post'&gt;&lt;input value='Checkout' type='submit'&gt;&lt;/form&gt;&lt;/div&gt;
&lt;div class='delete'&gt;&lt;form action='delete_items.php' target='Bottom Right Frame' method='post'&gt;&lt;input name='delete' value='Clear' type='submit'&gt;&lt;/form&gt;&lt;/div&gt;&lt;/th&gt;";
print "&lt;td&gt;Total Amount&lt;/td&gt;";
print "&lt;td&gt;$0&lt;/td&gt;";
print "&lt;/tr&gt;";
print "&lt;/table&gt;";
?&gt;
</code></pre>
