browse_prints.php
<?php
// This page displays the available prints (products).
// Set the page title and include the HTML header.
$page_title = 'Browse the Prints';
require_once ('./mysql_connect.php'); // Connect to the database.
//Are we looking at a particular artist?
if (isset($GET['aid'])) {
$query = "SELECT FROM category, product WHERE category.category_id = product.category_id AND product.category_id = {$GET['aid']} ORDER BY product.product_name";
} else {
$query = "SELECT FROM category, product WHERE category.category_id = product.category_id ORDER BY category.last_category ASC, product.product_name ASC";
}
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="20%"><b>Author</b></td>
<td align="left" width="20%"><b>Book Title</b></td>
<td align="left" width="40%"><b>Description</b></td>
<td align="right" width="20%"><b>Price</b></td>
</tr>';
// Display all the URLs.
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Display each record.
echo " <tr>
<td align=\"left\"><a href=\"browse_prints.php?aid={$row['category_id']}\"> {$row['last_category']}, {$row['first_category']} {$row['middle_category']}</a></td>
<td align=\"left\"><a href=\"view_print.php?pid={$row['product_id']}\">{$row['product_name']}</td>
<td align=\"left\">" . stripslashes($row['description']) . "</td>
<td align=\"right\">\${$row['price']}</td>
</tr>\n";
} // End of while loop.
echo '</table>'; // Close the table.
mysql_close(); // Close the database connection.
?>
view_cart.php
<?php
// This page displays the contents of the shopping cart.
session_start();
// Set the page title and include the HTML header.
$page_title = 'View Your Shopping Cart';
include_once ('includes/header_customer_two.html');
// Check if the form has been submitted (to update the cart)
if (isset ($_POST['submit'])) {
foreach ($_POST['qty'] as $key => $value) {
if (($value == 0) AND (is_numeric ($value))) {
unset ($_SESSION['cart'][$key]);
} elseif ( is_numeric ($value) AND ($value > 0) ) {
$_SESSION['cart'][$key] = $value;
}
}
}
// Check if the shopping cart is empty.
$empty = TRUE;
if (isset ($SESSION['cart'])) {
foreach ($SESSION['cart'] as $key => $value) {
if (isset($value)) {
$empty = FALSE;
}
}
}
// Display the cart if it's not empty.
if (!$empty) {
require_once ('./mysql_connect.php'); // Connect to the database.
// Retrieve all of the information for the prints in the cart.
$query = 'SELECT * FROM category, product WHERE category.category_id = product.category_id AND product.product_id IN (';
foreach ($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY category.last_category ASC';
$result = mysql_query ($query);
// Create a table and a form.
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="30%"><b>Author</b></td>
<td align="left" width="30%"><b>Book Title</b></td>
<td align="right" width="10%"><b>Price</b></td>
<td align="center" width="10%"><b>Qty</b></td>
<td align="right" width="10%"><b>Total Price</b></td>
</tr>
<form action="view_cart.php" method="post">
';
// Print each item.
$total = 0; // Total cost of the order.
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
// Calculate the total and subtotals.
$subtotal = $_SESSION['cart'][$row['product_id']] * $row['price'];
$total += $subtotal;
// Print the row.
echo " <tr>
<td align=\"left\">{$row['first_category']} {$row['middle_category']} {$row['last_category']}</td>
<td align=\"left\">{$row['product_name']}</td>
<td align=\"right\">\${$row['price']}</td>
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['product_id']}]\" value=\"{$_SESSION['cart'][$row['product_id']]}\" /></td>
<td align=\"right\">$" . number_format ($subtotal, 2). "</td>
</tr>\n";
} // End of the WHILE loop.
// Print the footer and close the table and the form.
echo ' <tr>
<td colspan="4" align="right"><b>Total : <b></td>
<td align="right">$' . number_format ($total, 2) . '</td>
</tr>
</table><div align="center"><input type="submit" name="submit" value="Update My Cart" /></form><br /><br /><a href="checkout.php"><font size="+3">Continue To Purchase</font></a></div>';
mysql_close(); // Close the database connection.
} else {
echo '<p>Your cart is currently empty.</p>';
}
?>
<PRE><?php
print_r($_SESSION);
?></PRE>
view_print.php
<?php
// This page displays the details for a particular print.
if (is_numeric ($_GET['pid'])) {
// Make sure there's a print ID.
require_once ('./mysql_connect.php'); // Connect to the database.
$query = "SELECT * FROM category, product WHERE category.category_id = product.category_id AND product.product_id = {$_GET['pid']}";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
mysql_close(); // Close the database connection.
// Set the page title and include the HTML header.
$page_title = $row['product_name'];
include_once ('includes/header_customer.html');
// Display a header.
echo "<div align=\"center\">
<b>{$row['product_name']}</b> by
{$row['first_category']} {$row['middle_category']} {$row['last_category']}
<br />{$row['description']}
<br />\${$row['price']}
<a href=\"add_cart.php?pid={$row['product_id']}\">Add to Cart</a>
</div><br />";
} else { // Redirect
header ("Location: [url]http://[/url]" . $SERVER['HTTP_HOST'] . dirname($SERVER['PHP_SELF']) . "/index.php");
exit();
}
?>
This is the script that deals with add_cart.php script.
Anyone out there can help me with my problem?