sandbudd
asked on
php cart throwing page not found
for example it is throwing page not found error this is the output ex... /addtocart.php?id=1025 I will attach a couple of pages.
First is the page to pull the database.
second is the addtocart.php
third is the
First is the page to pull the database.
second is the addtocart.php
third is the
<?php
require_once('library/init.php');
$page['products'] = $catalog->getCategories();
$scInfo = $catalog->getSubCategoryInfo($core->pageVar('sCatID', siteCore::VARTYPE_INT));
$page['content'] = "<h2><a href=\"category.php?catID=" . $scInfo['category']['id'] . "\">" .
$scInfo['category']['name'] . "</a> > " . $scInfo['name'] .
"</h2>\n<div class=\"mainContent\">\n";
$lastProdID = 0;
$lastWeight = 0;
$lastBrand = 0;
$first = 0;
$last = 0;
if(count($scInfo['products']))
{
$page['content'] .= "<ul>\n";
foreach($scInfo['products'] as $productID => $productInfo)
{
if(($lastProdID!=$productInfo['ProductIDtwo'] || $lastWeight!=$productInfo['weight']) && $last == 1)
{
$page['content'] .= "</table>";
$last = 0;
}
if($lastBrand!=$productInfo['brandID'])
{
if($first != 1)
{
$page['content'] .= "</table>";
}
$first = 2;
$lastBrand = $productInfo['brandID'];
$page['content'] .= "<h3><a href=\"brand.php?bID=$lastBrand\">" . $productInfo['brand'] . "</a></h3>";
$page['content'] .= "<table border=\"0\">";
}
if($lastProdID!=$productInfo['ProductIDtwo'] || $lastWeight!=$productInfo['weight'])
{
$page['content'] .= "<tr><td>";
//Delete this & update dB
if($productInfo['productPic'] == NULL) $productInfo['productPic'] = 'No Image.gif';
$page['content'] .= "<img src=\"Images/Product Images/" . $productInfo['productPic'] . "\" />";
$page['content'] .= "</td><td>";
$page['content'] .= "<name>" . $productInfo['name'] . "</name><br></a>";
if($productInfo['numUnits'] !== NULL) $page['content'] .= $productInfo['numUnits'] . "/";
$page['content'] .= $productInfo['weight'];
$page['content'] .= " " . $productInfo['unit'] . "<br>";
$page['content'] .= "$" . $productInfo['price'] . "\n";
$lastProdID = $productInfo['ProductIDtwo'];
$lastWeight = $productInfo['weight'];
if($productInfo['flavor'] == NULL)
{
$page['content'] .= "<h8><a href=\"addtocart.php?id=$productID\">" . " <form action='addtocart.php' method='post'>
<input type='hidden' name='productid' value='$pid'/>
<input type='submit' value='Add To Cart'/>" . "<br></a></h8>";
} else {
$page['content'] .= "<table cellpadding=\"0\" cellspacing=\"0\"><td>";
$page['content'] .= $productInfo['flavor'] . "  </td>";
$page['content'] .= "<td><h8><a href=\"addtocart.php?id=$productID\">" . " <form action='addtocart.php' method='post'>
<input type='hidden' name='productid' value='$pid'/>
<input type='submit' value='Add To Cart'/>" . "<br></a></h8></td></tr>";
$last = 1;
}
} else {
$page['content'] .= "<tr><td>";
$page['content'] .= $productInfo['flavor'] . "  </td>";
$page['content'] .= "<td><h8><a href=\"addtocart.php?id=$productID\">" . " <form action='addtocart.php' method='post'>
<input type='hidden' name='productid' value='$pid'/>
<input type='submit' value='Add To Cart'/>" . "<br></a></h8></td></tr>";
$last = 1;
}
}
}
$page['content'] .= "</td></tr></table></table>";
$page['content'] .= "</div>";
print_page();
?>
addtocart.php
<?php
/**
* First things first, get the product id that is to be added.
*/
if (isset($_POST['productID']))
{
/**
* By forcing this into int format, we avoid SQL Injection.
*/
$pid = intval($_POST['productID']);
}
else
{
throw new IllegalProductIDException();
}
/**
* Next, have the CartManager go and add an entry for this pid
* in the shopping cart. It is smart enough to know to
* see if there is an existing entry in the cart and simply
* increment the number of items desired when it exists.
*
* This method throws if it is not given a valid product id.
*/
$cm = CartManager::getInstance();
$cm->addProductToUserCart($pid);
/**
* Great. Now redirect them to the page to show them the
* contents of their cart.
*/
header('Location: SHOWCART.PHP');
?>
showcart.php
<?php
ob_start();
$page_title = "Shopping Cart Contents";
require_once('coreincs.inc');
require_once('pagetop.inc');
/**
* First, make sure there is a valid session.
*/
$sid = session_id();
if ($sid === NULL or $sid == '' or !isset($_SESSION))
{
throw new NoSessionException();
}
/**
* Now get the cart information from the session data.
*/
$cm = CartManager::getInstance();
$cart = $cm->getCartContents();
?>
<font class='pageBody'>
<!--
Keep Shopping and Proceed to Checkout buttons
-->
<br/>
<table align='center' width='50%' border='0' cellspacing='0'
cellpadding='0'>
<tr>
<td width='50%' align='right'>
<form action='showprods.php'>
<input type='submit' value='Keep Shopping'/>
</form>
</td>
<td width='50%' align='left'>
<form action='checkout.php' method='post'>
<input type='submit' value='Proceed to Checkout'/>
</form>
</td>
</tr>
</table>
<!--
Title row for the main shopping cart table
-->
<table align='center' border='1' width='90%' cellspacing='0'
cellpadding ='4'>
<tr>
<td width='40%'><br/><b>Title:</b></td>
<td width='20%'><br/><b>Price Each:</b></td>
<td width='20%'><br/><b>Quantity:</b></td>
<td width='20%'><br/><b>Total:</b></td>
</tr>
<?php
/**
* Okay, now go and create one row for each type of item in
* the shopping cart
*/
$subtotal = 0.0;
if (count($cart) == 0)
{
echo <<<EOTR
<tr>
<td colspan='4'>
Your shopping cart is empty at this time.
</td>
</tr>
EOTR;
}
else
{
echo <<<EOTEXT
<tr>
<td colspan='4'>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
EOTEXT;
foreach ($cart as $cartentry)
{
$total = (float)($cartentry->PricePerUnit)
* $cartentry->NumItems;
$subtotal += $total;
echo <<<EOTR
<tr>
<td width='40%' valign='top' align='center'>
{$cartentry->Title}
</td>
<td width='20%' valign='top' align='center'>
{$cartentry->PricePerUnit}
</td>
<td width='20%' valign='top' align='left' valign='center'>
<form action='updatequantity.php' method='post'>
<input type='hidden' name='productid'
value='{$cartentry->ProductID}'/>
<input type='text' size='2' name='quantity'
value='{$cartentry->NumItems}'/>
<input type='submit' value='Update'/>
</form>
</td>
<td width='20%' valign='top' align='center'>\$$total</td>
</tr>
EOTR;
}
echo <<<EOTEXT
</table>
</td>
</tr>
EOTEXT;
}
?>
<!--
Subtotal row for the shopping cart table.
-->
<tr>
<td colspan='3' align='right'>
Subtotal:
</td>
<td align='center' width='20%'>
<b>$<?php echo $subtotal; ?></b>
</td>
</tr>
</table>
<!--
One more set of "Keep Shopping" and "Proceed to Checkout"
Buttons.
-->
<br/>
<table align='center' width='50%' border='0' cellspacing='0'
cellpadding='0'>
<tr>
<td width='50%' align='right'>
<form action='showprods.php'>
<input type='submit' value='Keep Shopping'/>
</form>
</td>
<td width='50%' align='left'>
<form action='checkout.php'>
<input type='submit' value='Proceed to Checkout'/>
</form>
</td>
</tr>
</table>
</font>
<?php
/**
* Close out the page.
*/
require_once('pagebottom.inc');
ob_end_flush();
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.