Solved

php cart throwing page not found

Posted on 2008-10-26
2
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

724 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