Solved

php cart throwing page not found

Posted on 2008-10-26
2
501 Views
Last Modified: 2013-12-13
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
<?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>&nbsp;&gt;&nbsp;" . $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'] . "&nbsp&nbsp</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'] . "&nbsp&nbsp</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:&nbsp;&nbsp;
  </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();
?>

Open in new window

0
Comment
Question by:sandbudd
2 Comments
 
LVL 5

Accepted Solution

by:
DecKen earned 500 total points
ID: 22811086
On line 117 you have header('Location: SHOWCART.PHP'); do you have any issues if you open this page directly in IE?
 You could try changing line 117 to header('Location: showcart.php');  as it may be case sensitive depending on your webserver


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question