I don't know exactly what you are trying to accomplish, and of course I don't have your database. I have taken the liberty of making a small database containing product id and product name. It contains three items. When the page is first accessed, it is in "Catalog" mode and presents all three items with a checkbox for each. When you select items and click on "Select" the request is tendered again with the selected items being sent to the server via the "Get" method. The server responds and resends the page in "Cart" mode, showing only those items which were selected. It removes the "Select button and adds a second form with a "Catalog" button that submits via the "Post" method. This means that on submissions of the "Post" type, the "Get" array will be empty, and the page will perform as from the beginning. You may see this
here. The code is:
[php]
<?php
require_once ("functions.php");
$secondRequest = count ($_GET);
// Open the database
demoConnect ();
$queryProducts = "SELECT ProductID, ProductName
FROM Demonstration
ORDER BY ProductID";
$catalog = mysql_query ($queryProducts) or die (mysql_error()."product query");
if ($secondRequest) $pageType = 'Cart';
else $pageType = 'Catalog';
$title = '<p style="text-align: center; font-weight: bold; font-size: larger; padding: 5px;">';
$title .= $pageType;
$title .= '</p>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
td
{
border: 1px solid #000000;
padding: 10px;
}
.products
{
border: 1px solid #000000;
}
.head
{
font-weight: bold;
text-align: center;
}
.num
{
text-align: right;
}
.name
{
text-align: left;
}
.box
{
text-align: center;
}
</style>
<title>Checkbox Check</title>
</head>
<body>
<?php echo $title;?>
<form action="cbox.php" method="get" name="productSelect">
<table class="products" align="center" width="40%">
<tr>
<td class="head">Product ID</td>
<td class="head">Product Name</td>
<td class="head">Select</td>
</tr>
<?php
$count = 0;
$catalog = mysql_query ($queryProducts) or die (mysql_error()."product query");
while ($rowData = mysql_fetch_array ($catalog))
{
$box = 'CB'.$count;
if (!empty ($_GET [$box])) $checked = 'checked'; else $checked = '';
if (!$secondRequest || $checked)
{
echo '<tr>';
echo '<td class="num">'.$rowData ['ProductID'].'</td>';
echo '<td class="name">'.$rowData ['ProductName'].'</td>';
echo '<td class="box"><input name="CB'.$count.'" type="checkbox" ';
echo $checked.'></td>';
echo '</tr>';
}
$count++;
}
?>
</table>
<?php
if (!$secondRequest) echo <<< qqqq
<div align="center" style="padding: 20px;">
<input name="pSelect" type="submit" value="Select">
</div>
</form>
qqqq;
else echo <<< qqqq
</form>
<form action="cbox.php" method="post" name="showCatalog">
<div align="center" style="padding: 20px;">
<input name="pReturn" type="submit" value="Catalog">
</div>
</form>
qqqq;
?>
</body>
</html>
[/php]
Perhaps this will give some ideas on the various ways to accomplish these kinds of interactions.