nicky
12-07-2010, 02:43 PM
I am developing a catalog that customers can select from, then sends them to a "Request a Quote" form. All the items in the catalog are in a MySQL database. On the products page, I first selected only the product names from the database. Then when they click on the product name, the page reloads to display all the part numbers for that particular product. From there they can check the checkbox to send the part numbers to the request a quote form, however, from the RFQ form, I would like to enable the option to go back and continue adding items to the form, yet I can't seem to figure out PHP sessions. It's driving me bonkers!
products.php
include("header.php");
include("config.php");
include("connect.php");
if(!isset($_GET['item'])) {
$sql="SELECT DISTINCT product FROM $tbl_name";
}
else {
$sql="SELECT * FROM $tbl_name WHERE product = '" . addslashes($_GET['item']) . "'";
}
$result=mysql_query($sql) or die(mysql_error());
if(!isset($_GET['item'])) {
echo "<table>
<tr>
<th>Product</th>
</tr>";
}
else {
echo "<h1>{$_GET['item']}</h1>
<form action=\"quote.php\" method=\"post\">
<table style=\"width:100%;\">
<tr>
<th>Part Num</th>
<th>Description</th>
<th>Finish</th>
<th>Dem A</th>
<th>Dem B</th>
<th>Dem C</th>
<th>Dem D</th>
<th>Dem E</th>
<th>Dem F</th>
<th></th>
</tr>";
}
while($rows=mysql_fetch_array($result)){
if(!isset($_GET['item'])) {
echo "<tr>
<td><a href=\"?item={$rows['product']}\">{$rows['product']}</a></td>
</tr>";
}
else {
echo "<tr>
<td>{$rows['part_num']}</td>
<td>{$rows['description']}</td>
<td>{$rows['finish']}</td>
<td>{$rows['dem_a']}</td>
<td>{$rows['dem_b']}</td>
<td>{$rows['dem_c']}</td>
<td>{$rows['dem_d']}</td>
<td>{$rows['dem_e']}</td>
<td>{$rows['dem_f']}</td>
<td>{$rows['dem_g']}</td>
<td><input name=\"partnum[]\" type=\"checkbox\" value=\"{$rows['part_num']}\"></td>
</tr>";
}
}
if (!isset($_GET['item'])) {
echo "</table>"; }
else {
echo "<tr>
<td colspan=\"10\"><input name=\"add\" type=\"submit\" id=\"add\" value=\"Request a Quote\"/></td>
</tr>
</table>
</form>";
}
mysql_close();
include("footer.php");
quote.php
$partnum = $_REQUEST['partnum'];
$N = count($partnum);
for ($i=0; $i < $N; $i++) {
$_SESSION['Part'] = '$partnum[$i]';
}
include("header.php"); ?>
<h1>Request a Quote</h1>
<p><a href="products.php">Continue Shopping</a></p>
<p><?php echo $_SESSION['Part'];?></p>
<table>
<tr>
<td><label for="name">Name:</label></td>
<td colspan="2"><input type="text" id="name" name="name" size="35"/></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td colspan="2"><input type="text" id="email" name="email" size="35"/></td>
</tr>
<tr>
<td class="center" colspan="3">Specify the Quantity</td>
</tr>
<?php for($i=0; $i < $N; $i++) { echo "<tr>\n\t\t <td></td>\n\t\t <td>$partnum[$i]</td>" . "\n\t\t <td><input type=\"text\" name=\"quantity[]\" size=\"3\"/>" . "</td>\n\t\t</tr>\n\t\t"; } ?>
<tr>
<td colspan="3" class="center"><input type="submit" value=" Request a Quote "/> <input type="reset" value=" Reset Form "/></td>
</tr>
</table>
<?php include("footer.php");
Any help would be appreciated. Thank you!
products.php
include("header.php");
include("config.php");
include("connect.php");
if(!isset($_GET['item'])) {
$sql="SELECT DISTINCT product FROM $tbl_name";
}
else {
$sql="SELECT * FROM $tbl_name WHERE product = '" . addslashes($_GET['item']) . "'";
}
$result=mysql_query($sql) or die(mysql_error());
if(!isset($_GET['item'])) {
echo "<table>
<tr>
<th>Product</th>
</tr>";
}
else {
echo "<h1>{$_GET['item']}</h1>
<form action=\"quote.php\" method=\"post\">
<table style=\"width:100%;\">
<tr>
<th>Part Num</th>
<th>Description</th>
<th>Finish</th>
<th>Dem A</th>
<th>Dem B</th>
<th>Dem C</th>
<th>Dem D</th>
<th>Dem E</th>
<th>Dem F</th>
<th></th>
</tr>";
}
while($rows=mysql_fetch_array($result)){
if(!isset($_GET['item'])) {
echo "<tr>
<td><a href=\"?item={$rows['product']}\">{$rows['product']}</a></td>
</tr>";
}
else {
echo "<tr>
<td>{$rows['part_num']}</td>
<td>{$rows['description']}</td>
<td>{$rows['finish']}</td>
<td>{$rows['dem_a']}</td>
<td>{$rows['dem_b']}</td>
<td>{$rows['dem_c']}</td>
<td>{$rows['dem_d']}</td>
<td>{$rows['dem_e']}</td>
<td>{$rows['dem_f']}</td>
<td>{$rows['dem_g']}</td>
<td><input name=\"partnum[]\" type=\"checkbox\" value=\"{$rows['part_num']}\"></td>
</tr>";
}
}
if (!isset($_GET['item'])) {
echo "</table>"; }
else {
echo "<tr>
<td colspan=\"10\"><input name=\"add\" type=\"submit\" id=\"add\" value=\"Request a Quote\"/></td>
</tr>
</table>
</form>";
}
mysql_close();
include("footer.php");
quote.php
$partnum = $_REQUEST['partnum'];
$N = count($partnum);
for ($i=0; $i < $N; $i++) {
$_SESSION['Part'] = '$partnum[$i]';
}
include("header.php"); ?>
<h1>Request a Quote</h1>
<p><a href="products.php">Continue Shopping</a></p>
<p><?php echo $_SESSION['Part'];?></p>
<table>
<tr>
<td><label for="name">Name:</label></td>
<td colspan="2"><input type="text" id="name" name="name" size="35"/></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td colspan="2"><input type="text" id="email" name="email" size="35"/></td>
</tr>
<tr>
<td class="center" colspan="3">Specify the Quantity</td>
</tr>
<?php for($i=0; $i < $N; $i++) { echo "<tr>\n\t\t <td></td>\n\t\t <td>$partnum[$i]</td>" . "\n\t\t <td><input type=\"text\" name=\"quantity[]\" size=\"3\"/>" . "</td>\n\t\t</tr>\n\t\t"; } ?>
<tr>
<td colspan="3" class="center"><input type="submit" value=" Request a Quote "/> <input type="reset" value=" Reset Form "/></td>
</tr>
</table>
<?php include("footer.php");
Any help would be appreciated. Thank you!