Jump to content

Recommended Posts

if someone could PPPPPPPPPPLLLLLEEEEEEEEAAAAAAASSSEEEEEE help me, I would really appreciate it. I got rid of the error message and if you click a treat on treats,php it will redirect to the checkout.php and it displays the table header but not the chosen treat.

 

treats.php

<?php
require_once("functions.php");
//session_name("treats");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auntie Vic's treats</title>
<link href="doggyTreats.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.product {
margin: 0 auto;
}
.product img {
float:left;
}
#mainContent {
margin: 0 auto;
text-align:center;
width:600px;
}
.description {
width: 200px;
padding-left: 5px;
}
.price {
font-weight: bold;
text-align:left;
clear:both;
}
.addToCart {
diaplay: block;
text-align:right;
}
#catalog {
margin-top: 50px;
margin-left: 250px;
}
.products {
width: 300px;
text-align:center;
padding-right:35px;
padding-bottom: 6px;
}
.pics {
text-align:center;
}
.description {
padding-right: 25px;
}
</style>
</head>

<body>
<div id = "navBar">
<ul id="menu">
<li class="menuOption"><a href="index.html">Home</a></li>
<li class="menuOption"><a href="aboutUs.html">Management Team </a></li>
<li class="menuOption"><a href="missionStatement.html">Mission Statement</a></li>
<li class="menuOption"><a href="treats.html">Treats </a></li>
<li class="menuOption"><a href="charities.html">Supported Charities</a></li>
<li class="menuOption"><a href="order.html">Orders</a></li>
</ul>
</div>
<div id="logo"><img src="assets/logo.gif" width="182" height="123" alt="logo" /></div>
<div id = "mainContent">

<?php
echo render_products_from_xml();
?>
</div>
<div id = "footer">
Auntie Vic's Treatery <br />
PO Box 34092 <br />
Clermont, IN 46234 <br />
317-701-0343 <br />
<a href="mailto:[email protected]">Email Us</a></div>
</body>
</html>

 

<?php
require_once("functions.php");
//session_name("treats");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auntie Vic's treats</title>
<link href="doggyTreats.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.product {
margin: 0 auto;
}
.product img {
float:left;
}
#mainContent {
margin: 0 auto;
text-align:center;
width:600px;
}
.description {
width: 200px;
padding-left: 5px;
}
.price {
font-weight: bold;
text-align:left;
clear:both;
}
.addToCart {
diaplay: block;
text-align:right;
}
#catalog {
margin-top: 50px;
margin-left: 250px;
}
.products {
width: 300px;
text-align:center;
padding-right:35px;
padding-bottom: 6px;
}
.pics {
text-align:center;
}
.description {
padding-right: 25px;
}
</style>
</head>

<body>
<div id = "navBar">
<ul id="menu">
<li class="menuOption"><a href="index.html">Home</a></li>
<li class="menuOption"><a href="aboutUs.html">Management Team </a></li>
<li class="menuOption"><a href="missionStatement.html">Mission Statement</a></li>
<li class="menuOption"><a href="treats.html">Treats </a></li>
<li class="menuOption"><a href="charities.html">Supported Charities</a></li>
<li class="menuOption"><a href="order.html">Orders</a></li>
</ul>
</div>
<div id="logo"><img src="assets/logo.gif" width="182" height="123" alt="logo" /></div>
<div id = "mainContent">

<?php
echo render_products_from_xml();
?>
</div>
<div id = "footer">
Auntie Vic's Treatery <br />
PO Box 34092 <br />
Clermont, IN 46234 <br />
317-701-0343 <br />
<a href="mailto:[email protected]">Email Us</a></div>
</body>
</html>

 

shoppingcart.php

<?php
class shoppingCart {
protected $items = array();
public function addItem($product_id)
{
if (array_key_exists($product_id , $this->items))
$this->items[$product_id] = ($this->items[$product_id] +1);
else
$this->item[$product_id] = 1;
}
/*video 8 public function GetItemCost($product_id)
{
$cost_string = get_item_cost($product_id);
$cost_float = %cost_string + 0;

return $cost_float * $this->GetItemQuanity[$product_id]);
}*/
public function getItems()
{
return array_keys($this->items);
}
public function GetItemQuuanity($product_id)
{
return $this->item[$product_id];
}
}
?>

 

functions.php

<?php
require_once('classes/shoppingCart.php');
/**DEFINE GLOBALS**/
define('STORE_XML_FILE' , 'catalog.xml');

/*FUNCTIONS*/
session_start();

function render_products_from_xml()
{
$output = '.<table class="product">
<tr>';
foreach(get_xml_catalog() as $product)
{
$output .='
<td class="product">
<h2>'.$product->title.'</h2>
<div>
<img src="'.$product->img. '" />
<span>
'.$product->description.'
</span>
</div>
<div class="price">
'.$price->price.'
</div>
<div class="addToCart">
<a href="checkOut.php?id='.$product->id.'">add to cart</a>

</div>
</td>';
}
$output .='
</tr>
</table>

';
echo $output;
}

function get_xml_catalog()
{
return new SimpleXMLElement(file_get_contents(STORE_XML_FILE));
}

function get_shopping_cart()
{

if (! isset($_SESSION['cart']))
return new shoppingCart(); //starts new cart
else
return unserialize($_SESSION['cart']);
}

function set_shopping_cart($cart)
{
$_SESSION['cart'] = serialize($cart);
}

function product_exist($product_id)
{
foreach(get_xml_catalog() as $product)
{
if ($product->id == $product_id)
return true;
}
return false;
}
//start of video 8
function get_item_price($product_id)
{
foreach(get_xml_catalog() as $product->id)
{
if ($product_id = $product->id)
return $product->price;
}
throw new Exception('item not found' . $product_id);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/244617-add-item-to-cart/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.