basketstatus.php is at the top,
basket.php:
<?
session_start();
$sessionid=session_id();
if (isset($_SESSION['username'])) {
$accepted='4';
}
else {
$accepted='0';
}
require "functions.php";
include "db.php";
$pagename='Your Basket';
pagetop($pagename, $accepted, $username);
$action=$_GET['action'];
$productid=$_GET['id'];
if ($action!=''){
if ($action=='add'){
$findsql="SELECT * from `basket` where productid='$productid' and `sessionid`='$sessionid'";
$dofind=mysql_query($findsql);
$rowsfound=mysql_num_rows($dofind);
if ($rowsfound>=1) {
echo 'This item was already found in your basket. To add more of the same item, please use the \'edit\' button within the basket itself.';
// update basket code:
$findcontent="SELECT basket.sessionid, basket.qty, basket.productid, products.productid, products.code, products.price, products.brand, products.rrp, products.productsort from basket, products where basket.sessionid='$sessionid' and products.productid=basket.productid";
$getcontent=mysql_query($findcontent);
$contentrows=mysql_num_rows($getcontent);
if ($contentrows>0) {
echo '
<table>
<tr>
<td class="basketHeader">
Code
</td>
<td class="basketHeader">
Price
</td>
<td class="basketHeader">
Qty
</td>
<td class="basketHeader">
Total
</td>
<td class="basketHeader">
Edit
</td>
</tr>
';
while ($contentrow = mysql_fetch_array($getcontent))
{
$code= $contentrow["code"];
$price= $contentrow["price"];
$qty= $contentrow["qty"];
$id= $contentrow["productid"];
$total=$qty*$price;
$grandtotal+=$total;
echo '
<tr>
<td>
'.$code.'
</td>
<td>
'.$price.'
</td>
<form name="update" method="post" action="basket.php?action=edit">';
if ($id==$productid) {
echo '
<td>
<input type="text" name="newqty" value='.$qty.' maxlength="3" size="3">
</td>
';
}
else {
echo '
<td>
'.$qty.'
</td>
';
}
echo'
<td>
'.$total.'
</td>
<td>
<input type="submit" value="update" name="update">
</td>
<input type="hidden" name="productid" value="'.$id.'">
</form>
</tr>
';
}
echo '
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="3" align="left">
Grand Total
</td>
<td colspan="" align="left">
'.$grandtotal.'
</td>
<td>
</td>
</tr>
<tr>
<td colspan="10" align="right">
<a href="checkout.php">go to checkout</a>
</td>
</tr>
</table>';
}
else {
echo 'Your basket is currently empty. <a href="products.php">Click here to view our products.</a>';
}
// end update basket code
}
else {
$addsql="INSERT into `basket` (`sessionid`, `productid`, `qty`) values ('$sessionid','$productid','1')";
$doadd=mysql_query($addsql);
include "showbasket.php";
}
}
else if ($action=='edit') {
if (isset($_POST['newqty'])) {
$newqty=$_POST['newqty'];
$productid=$_POST['productid'];
/*
$findcontent="SELECT basket.sessionid, basket.qty, basket.productid, products.productid, products.code, products.price, products.brand, products.rrp, products.productsort from basket, products where basket.sessionid='$sessionid' and products.productid=basket.productid";
$getcontent=mysql_query($findcontent);
$contentrows=mysql_num_rows($getcontent);
if ($contentrows>0) {
while ($contentrow = mysql_fetch_array($getcontent))
{
$code= $contentrow["code"];
$price= $contentrow["price"];
$qty= $contentrow["qty"];
}
}
else {}
*/
$updatesql="UPDATE `basket` set `qty`='$newqty' where `sessionid`='$sessionid' and `productid`='$productid'";
$doupdate=mysql_query($updatesql);
include "showbasket.php";
}
else {
$productidrequired=$_GET['productid'];
// update basket code:
$findcontent="SELECT basket.sessionid, basket.qty, basket.productid, products.productid, products.code, products.price, products.brand, products.rrp, products.productsort from basket, products where basket.sessionid='$sessionid' and products.productid=basket.productid";
$getcontent=mysql_query($findcontent);
$contentrows=mysql_num_rows($getcontent);
if ($contentrows>0) {
echo '
<table>
<tr>
<td class="basketHeader">
Code
</td>
<td class="basketHeader">
Price
</td>
<td class="basketHeader">
Qty
</td>
<td class="basketHeader">
Total
</td>
<td class="basketHeader">
Edit
</td>
</tr>
';
while ($contentrow = mysql_fetch_array($getcontent))
{
$code= $contentrow["code"];
$price= $contentrow["price"];
$qty= $contentrow["qty"];
$id= $contentrow["productid"];
$total=$qty*$price;
$grandtotal+=$total;
echo '
<tr>
<td>
'.$code.'
</td>
<td>
'.$price.'
</td>
<form name="update" method="post" action="basket.php?action=edit">';
if ($id==$productidrequired) {
echo '
<td>
<input type="text" name="newqty" value='.$qty.' maxlength="3" size="3">
</td>
';
}
else {
echo '
<td>
'.$qty.'
</td>
';
}
echo'
<td>
'.$total.'
</td>
<td>
<input type="submit" value="update" name="update">
</td>
<input type="hidden" name="productid" value="'.$id.'">
</form>
</tr>
';
}
echo '
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="3" align="left">
Grand Total
</td>
<td colspan="" align="left">
'.$grandtotal.'
</td>
<td>
</td>
</tr>
<tr>
<td colspan="10" align="right">
<a href="checkout.php">go to checkout</a>
</td>
</tr>
</table>';
}
else {
echo 'Your basket is currently empty. <a href="products.php">Click here to view our products.</a>';
}
// end update basket code
}
}
else if ($action=='delete') {
$productid=$_GET['productid'];
$deletesql="delete from `basket` where `sessionid`='$sessionid' and `productid`='$productid'";
$dodelete=mysql_query($deletesql);
include "showbasket.php";
}
else {}
}
else {
include "showbasket.php";
}
pagebottom();
?>