Hi Guys
I hava a page on my website that enables a customer to select a product, choose a colour and a size, create some custom text then send that data to my cart.php page. I'm not sure if I am doing this the correct way and havent done a cart before.
This form collects the data then posts it to the cart.php page and echo's it to the screen.
<form action="cart.php" method="POST">
<input type="hidden" name="category" id="category" value="<?php echo $_GET['cid']; ?>" />
<input type="hidden" name="name" id="name" value="<?php echo $_GET['nid']; ?>" />
<input type="hidden" name="colour" id="colour" value="<?php echo $_GET['colid']; ?>" />
<input type="hidden" name="input" id="input" value="<?php echo $_POST['input']; ?>" />
<input type="hidden" name="fontselect" id="fontselect" value="<?php echo $_POST['fontselect']; ?>" />
<input type="hidden" name="sizeselect" id="sizeselect" value="<?php echo $_POST['sizeselect']; ?>" />
<div class="textinputgo"><input name="cart" type="submit" id="cart" value="Add to Cart" /></div>
</form>
This is the cart.php page which displays the product selections on the page;
( I have used tables for now but will change these to divs.)
<h1>Shopping Cart</h1>
<?php
$submit = ($_POST['cart']);
if (!isset($submit)){
echo 'Your cart is empty';
}else {
//Form data
$category = ($_POST['category']);
$name = ($_POST['name']);
$colour = ($_POST['colour']);
$text = ($_POST['input']);
$font = ($_POST['fontselect']);
$size = ($_POST['sizeselect']);
if (isset($submit)){
// This page displays the contents of the shopping cart.
// Create a table and a form.
echo '<table border="1" border color="#ff9999" width="90%" cellspacing="3" cellpadding="3" align="left">
<tr>
<td align="left" width="15%"><b>Category</b></td>
<td align="left" width="15%"><b>Name</b></td>
<td align="left" width="15%"><b>Colour</b></td>
<td align="left" width="15%"><b>Text</b></td>
<td align="left" width="10%"><b>Font</b></td>
<td align="left" width="15%"><b>Size</b></td>
</tr>
';
echo '<tr>';
echo '<td align="left">' . $category . '</td>';
echo '<td align="left">' . $name . '</td>';
echo '<td align="left">' . $colour . '</td>';
echo '<td align="left">' . $text . '</td>';
echo '<td align="left">' . $font . '</td>';
echo '<td align="left">' . $size . '</td>';
echo '</tr>';
echo '</table>';
}
}
?>
My questions are;
How do I add the facility to increse the quantity of the products on the cart.php page?
If I go to another page then click on cart again the cart is empty so how do I keep the info in the cart? I'm assuming some sort of session but dont know how to do these.
Thanks guyz