Jump to content

error


mindapolis

Recommended Posts

What does this error mean?

 

Fatal error: Call to a member function getItems() on a non-object in D:\Hosting\5246561\html\checkOut.php on line 35

 

<?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;

}

public function getItems()

{

return array_keys($this->item);

}

public function GetItemQuuanity($product_id)

{

return $this->item[$product_id];

}

}

?>

 

 

<?php

require_once('functions.php');

?>

<!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>Untitled Document</title>

</head>

 

<body>

<?php

$shopping_cart = get_shopping_cart();

$product_id=$_REQUEST['id'];

if (product_exist($product_id))

{

$shopping_cart->addItem($product_id);

 

}

?>

<table class="shoppingCart">

<tr>

<th>

Produt ID

</th>

<th>

Quanity

</th>

<th>

Amount

</th>

</tr>

<?php

$line_item_counter = 1;

foreach ($shopping_cart->getItems() as $product_id)

{

echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter);

$line_item_counter++;

}

function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)

{

$quanity = $shopping_cart->GetItemQuanity($product_id);

$output = '

<tr>

<td>

$product_id

</td>

<td>

$quanity

</td>

<td>

$ amount

</td>

</tr>';

return $output;

}

?>

 

</table>

<?php

set_shopping_cart($shopping_cart);

?>

</body>

</html>

Link to comment
Share on other sites

I believe this is the line PHP is having an issue with:

 

foreach ($shopping_cart->getItems() as $product_id)

That error indicates you are calling a function (->getItems()) on a non-object -- which means that $shopping_cart isn't an object, and probably hasn't been initialized correctly somehow.

 

My first step in debugging this would be to add:

 

print_r($shopping_cart);
exit;

right after

 

$shopping_cart = get_shopping_cart();

and see what the page displays. My guess is here is some sort of issue with your get_shopping_cart() function, and it isn't getting the shopping cart properly for some reason.

 

As a side-note, in your code above, you've misspelled "quantity" several times, and the function name within the shopping cart class is also misspelled.

Link to comment
Share on other sites

It displays this now.

 

 

Warning: array_keys() [function.array-keys]: The first argument should be an array in D:\Hosting\5246561\html\classes\shoppingCart.php on line 13

 

Warning: Invalid argument supplied for foreach() in D:\Hosting\5246561\html\checkOut.php on line 35

Produt ID quantity Amount

 

 

Here's the code

<?php

require_once('functions.php');

?>

<!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>Untitled Document</title>

</head>

 

<body>

<?php

$shopping_cart = get_shopping_cart();

$product_id=$_REQUEST['id'];

if (product_exist($product_id))

{

$shopping_cart->addItem($product_id);

 

}

?>

<table class="shoppingCart">

<tr>

<th>

Produt ID

</th>

<th>

quantity

</th>

<th>

Amount

</th>

</tr>

<?php

$line_item_counter = 1;

foreach ($shopping_cart->getItems() as $product_id)

print_r($shopping_cart);

exit;

{

echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter);

$line_item_counter++;

}

function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)

{

$quantity = $shopping_cart->GetItemquantity ($product_id);

$output = '

<tr>

<td>

$product_id

</td>

<td>

$quantity

</td>

<td>

$ amount

</td>

</tr>';

return $output;

}

?>

 

</table>

<?php

set_shopping_cart($shopping_cart);

?>

</body>

</html>

'

Link to comment
Share on other sites

I did. Here's the code now. It should show the items picked from treats.php. I'm doing the shopping cart video series and I can't get past video 7

 

checkout page code

<?php

require_once('functions.php');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

$shopping_cart = get_shopping_cart();

$product_id=$_REQUEST['id'];

if (product_exist($product_id))

{

$shopping_cart->addItem($product_id);

}

?>

<table class="shoppingCart">

<tr>

<th>

Produt ID

</th>

<th>

quantity

</th>

<th>

Amount

</th>

</tr>

<?php

$line_item_counter = 1;

foreach ($shopping_cart->getItems() as $product_id)

{

echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter);

$line_item_counter++;

}

 

function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)

{

$quantity = $shopping_cart->GetItemquantity ($product_id);

$output = '

<tr>

<td>

$product_id

</td>

<td>

$quantity

</td>

<td>

$ $amount

</td>

</tr>';

return $output;

}

?>

 

</table>

<?php

set_shopping_cart($shopping_cart);

?>

</body>

</html>

 

 

treats page code

 

<?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:auntievics@gmail.com">Email Us</a></div>

</body>

</html>

 

 

function file

<?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="order.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['Get']);

}

 

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;

}

?>

Edited by mindapolis
Link to comment
Share on other sites

when I load cheekout.php I get shoppingCart Object ( [items:protected] => Array ( ) )

 

When I load treats.php it loads everything okay and when I hit "add to cart" it directs it to order.php. It directs it to this page whether or not

<?php

session_name("treats");

session_start();

?>

is on the page.

 

Ultimately, yes, items from treats.php will go on order.php, but I was using checkout.php as a testing page to get the shopping cart set up. not understanding why treats.php isn't directing items to checkout.php

order.php

<?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>ordering doggy treats</title>

<link href="doggyTreats.css" rel="stylesheet" type="text/css" />

<style type="text/css">

#order {

 

margin-right: auto;

margin-left: auto;

}

.orderRow{

padding-bottom: 50px;

}

h2 {

text-align: center;

}

 

</style>

</head>

<body>

<?php

//error code

echo <<<HEREDOC

<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="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>

<table id="order">

<form action="POST" method="post" name="order ">

 

<caption><h2>Customer Information </h2> </caption>

<tr class = "orderRow">

<td> First Name:<br />

<input name="fname" type="text" size="10" maxlength="20" />

</td>

<td> Last Name: <br />

<input name="lname" type="text" size="10" maxlength="20" />

</td>

<td> Address: <br />

<input name="address " type="text" size="25" />

</td>

</tr>

<tr class = "orderRow">

<td> City: <br />

<input name="city " type="text" size="15" maxlength="20" />

</td>

<td> State: <br />

<select name = "state"> <option selected value ="Please choose a state"/>

Please choose a state</option>

<option value = "AL" />AL</option>

<option value = "AK" />AK</option>

<option value = "AR" />AR</option>

<option value = "AZ" />AZ

<option value = "CA" />CA

<option value = "CO" />CO

<option value = "CT" />CT

<option value = "DE" />DE

<option value = "DC" />DC

<option value = "FL" />FL

<option value = "GA" />GA

<option value = "HI" />HI

<option value = "IA" />IA

<option value = "ID" />ID

<option value = "IL" />IL

<option value = "IN" />IN

<option value = "KS" />KS

<option value = "KY" />KY

<option value = "LA" />LA

<option value = "MA" />MA

<option value = "ME" />ME

<option value = "MD" />MD

<option value = "MI" />MI

<option value = "MN" />MN

<option value = "MO" />MO

<option value = "MS" />MS

<option value = "MT" />MT

<option value = "NC" />NC

<option value = "ND" />ND

<option value = "NE" />NE

<option value = "NH" />NH

<option value = "NJ" />NJ

<option value = "NM" />NM

<option value = "OH" />OH

<option value = "OK" />OK

<option value = "OR" />OR

<option value = "PA" />PA

<option value = "RI" />RI

<option value = "SC" />SC

<option value = "SD" />SD

<option value = "TN" />TN

<option value = "TX" />TX

<option value = "UT" />UT

<option value = "VA" />VA

<option value = "VT" />VT

<option value = "WA" />WA

<option value = "WI" />WI

<option value = "WV" />WV

<option value = "WY" />WY

</select>

</td>

<td> Zip Code:<br />

<input name="zipcode" type="text" size="5" maxlength="5" />

</td>

</tr>

<tr class = "orderRow">

<td> Phone <br /> Please include area code <br />

<input name="phone" type="text" size="13" maxlength="13" />

</td>

<td> Fax:<br />

<input name="" type="text" size="13" maxlength="13" />

</td>

<td> Email: <br />

<input name="email " type="text" size="15" maxlength="30" />

</td>

</tr>

<tr class = "orderRow">

<td> Please choose method of payment: <br />

Check <input name="check " type="radio" value="Check " /> Money Order <input name="money " type="radio" value="Money order " /><br />PayPal<input name="paypal" type="radio" value="Paypal" /> </td>

</tr>

<tr>

<td colspan = "6"> <h2> Pet Information </h2></td>

</tr>

<tr>

<td> Name: <br />

<input name="petName" type="text" size="10" maxlength="20" />

</td>

<td> Age: <br />

<select name="age">

HEREDOC;

for ($age =1; $age <=20; $age ++)

{

print "<option value=\"age\"> $age</option>";

}

echo <<<HEREDOC

</select>

</td>

<td> Breed:<br />

<select name = "breed"> <option selected value ="Please choose a breed"/>

Please choose a breed

<option value = "I don't know" />I don't know

<option value = "Affernpincher" />Affernpincher

<option value = "Afghan Hound" />Afghan Hound

<option value = "Airedale Terrier" /> Airedale Terrior

<option value = "Akita" /> Akita

<option value = "Alaskan Malamute" /> Alaskan Malamute

<option value = "Standard American Eskimo Dog"/> Standard American Eskimo Dog

<option value = "Miniature American Eskimo Dog"/>Miniature American Eskimo Dog

<option value = "Toy American Eskimo Dog"/> Toy American Eskimo Dog

<option value = "American Foxhound" /> American Foxhound

<option value = "American Staffordshire Terrier" /> American Staffordshhire Terrier

<option value = "American Water Spaniel" /> American Water Spaniel

<option value = "Australian Shepherd Dog"/> Anatolian Shepherd Dog

<option value = "Australian Cattle Dog"/> Australian Cattle Dog

<option value = "Australian Shepherd"/> Australian Shepherd

<option value = "Australian Terrier" /> Australia Terrier

<option value = "Basenji" /> Basenji

<option value = "Basset Hound" /> Basset Hound

<option value = "Beagle" /> Beagle

<option value = "Bearded Collie" /> Bearded Collie

<option value = "Beauceron" /> Beauceron

<option value = "Bedington Terrier"/> Bedington Terrier

<option value = "Belgin Malinois"/> Belgin Malinois

<option value = "Belgian Sheepdog"/> Belgian Sheepdog

<option value = "Belgian Tervuren"/> Belgian Tervuren

<option value = "Bernese Mountain Dog"/> Bernese Mountain Dog

<option value = "Bichon Frise"/> Bichon Frise

<option value = "Black and Tan Greyhound" /> Black and Tan Greyhound

<option value = "Black Russian Terrier" /> Black Russian Terrier

<option value = "Bloodhoung" /> Bloodhound

<option value = "Border Collie" /> Border Collie

<option value = "Border Terrier"/> Border Terrier

<option value = "Borzoi"/> Borzoi

<option value = "Boston Terrier"/> Boston Terrier

<option value = "Bouvier des Flandres"/> Bouvier des Flandres

<option value = "Boxer"/> Boxer

<option value = "Briard"/> Briard

<option value = "Brittany" /> Brittany

<option value = "Brussels Griffon" /> Brussels Griffon

<option value = "Bulldog" /> Bulldog

<option value = "Bullmastiff" /> Bullmasttiff

<option value = "Bull Terrier" /> Bull Terrier

<option value = "Cairn Terrier" /> Cairn Terrier

<option value = "Canaan Dog" /> Canaan Dog

<option value = "Cardigan Welsh Corgi" /> Cardigan Welsh Corgi

<option value = "Cavalier King Charles Spaniel" />Cavalier King Charles Spaniel

<option value = "Chesepeake Bay Retriever" />Chesapeake Bay Retriever

<option value = "Chilauhua" /> Chilauhua

<option value = "Chinese Created" /> Chinese Crested

<option value = "Chinese Shar-Pei" /> Chinese Shar-Pei

<option value = "Chow Chow" /> Chow Chow

<option value = "Clumber Spaniel" /> Clumber Spaniel

<option value = "Cocker Spaniel" /> Cocker Spaniel

<option value = "Collie" /> Collie

<option value = "Curly-Coated Retrieve" /> Curly-Coated Retriever

<option value = "Dachshound" /> Dachshund

<option value = "Dalmation" /> Dalmation

<option value = "Dandle Dimonnt" /> Dandie Dinmont Terrier

<option value = "Doberman Pincher" /> Doberman Pincher

<option value = "Dogue de Bordeaux" /> Dogue de Bordeaux

<option value = "English Cocker Spaniel" /> English Cocker Spaniel

<option value = "English Foxhound" /> English Foxhound

<option value = "English Setter" /> English Setter

<option value = "English Springer" /> English Springer

<option value = "English Toy Spaniel" /> English Toy Spaniel

<option value = "Field Spaniel" /> Field Spaniel

<option value = "Finnish Spitz" /> Finnish Spitz

<option value = "Flat-Coated Retriever" /> Flat-Coated Retriever

<option value = "French Bulldog" /> French Bulldog

<option value = "German Shepherd Dog" /> German Shepherd Dog

<option value = "German Shorthaired Pointer"/>German Shorthaired Pointer

<option value = "German Wirehaired Pointer" /> German Wirehaired Pointer

<option value = "Giant Schnauzer" /> Giant Schnauzer

<option value = "Glen of Imaal Terrier" /> Glen of Imaal Terrier

<option value = "Golden Retriever" /> Golden Retriever

<option value = "Gorden Setter" /> Gorden Setter

<option value = "Great Dane" /> Great Dane

<option value = "Greater Swiss Mountain Dog" /> Greater Swiss Mountain Dog

<option value = "Great Pyrenees" /> Great Pyrenees

<option value = "Greyhound" /> Greyhound

<option value = "Harrier" /> Harrier

<option value = "Havanese" /> Havanese

<option value = "Ibizen Hound" /> Ibizen Hound

<option value = "Irish Setter" /> Irish Setter

<option value = "Irish Terrier" /> Irish Terrier

<option value = "Irish Water Spaniel" /> Irish Water Spaniel

<option value = "Irish Wolfhound" /> Irish Wolfhound

<option value = "Italian Greyhound" /> Italian Greyhound

<option value = "Jack Russell Terrier" /> Jack Russell Terrier

<option value = "Japanese Chin" /> Japanese Chin

<option value = "Keeshound" /> Keeshound

<option value = "Kerry Blue TErrier" /> Kerry Blue Terrier

<option value = "Komondor" /> Komondor

<option value = "Kuvasz" /> Kuvasz

<option value = "Labradar Retriever" /> Labrador Retriever

<option value = "Lakeland Terrier" /> Lakeland Terrier

<option value = "Lhasa Apso" /> Lhasa Apso

<option value = "Lowchen" /> Lowchen

<option value = "Maltese" /> Maltese

<option value = "Standard Manchester Terrier" /> Standard Manchester Terrier

<option value = "Mastiff" /> Mastiff

<option value = "Miniature Bull Terrier" /> Miniature Bull Terrier

<option value = "Miniature Pinche" /> Miniature Pinscher

<option value = "Miniature Poodle" /> Miniature Poodle

<option value = "Miniature Schnauzer" />Miniature Schnauzer

<option value = "Mutt" />Mutt

<option value = "Neopolitan Mastiff" />Neopolitan Mastiff

<option value = "Newfoundland&nbsp" /> Newfoundland

<option value = "Newfolk Terrier" />Norfolk Terrier

<option value = "Norwegian Elkhound" /> Norwegian Elkhound

<option value = "Norwich Terrier" /> Norwich Terrier

<option value = "Nova Scotia Duck Tolling Retriever" /> Nova Scotia Duck Tolling Retriever

<option value = "Old English Sheepdog" />Old English Sheepdog

<option value = "Otterhound" /> Otterhound

<option value = "Papillon" />Papillon

<option value = "Parson Russell Terrier" /> Parson Russell Terrier

<option value = "Pekingese" />Pekingese

<option value = "Pembroke Welsh Corgi" />Pembroke Welsh Corgi

<option value = "Petit Basset Griffon Vendeen" />Petit Basset Griffon Vendeen

<option value = "Pharch Hound" />Pharoh Hound

<option value = "Plott" /> Plott

<option value = "Pointer" /> Pointer

<option value = "Polish Lowland Sheepdog" />Polish Lowland sheepdog

<option value = "Pomeranian" /> Pomeranian

<option value = "Portuguese Water Dog" />Portuguese Water Dog

<option value = "Pug" />Pug

<option value = "Pull" />Puli

<option value = "Rhodesian Ridgeback" />Rhodesian Ridgeback

<option value = "Rottweiler" />Rottweiler

<option value = "ASaint Bernard" /> Saint Bernard

<option value = "Saluki" /> Saluki

<option value = "Samoyed" />Samoyed

<option value = "Schipperke" />Schipperke

<option value = "Scottish Doverhound" />Scottish Deerhound

<option value = "Scottish Terrier" />Scottish Terrier

<option value = "Sealyham Terrier" />Sealyham Terrier

<option value = "Shetland Sheepdog" />Shetland Sheepdog

<option value = "Shiba Inu" />Shiba Inu

<option value = "Shih Tzu" />Shih Tzu

<option value = "Siberian Husky" />Siberian Husky

<option value = "Silky Terrier" />Silky Terrier

<option value = "Skye Terrier" />Skye Terrier

<option value = "Smooth Fox Terrier" />Smooth Fox Terrier

<option value = "Soft Coated Wheaten Terrier" />Soft Coated wheaten Terrier

<option value = "Spinone Italiano" />Spinone Italiano

<option value = "Staffordshire Bull Terrier" />Staffordshire Bull Terrier

<option value = "Standard Poodle" />Standard Poodle

<option value = "Standard Schnauer" /> Standard Schnauzer

<option value = "Suseex Spaniel" />Sussex Spaniel

<option value = "Swedish Vallhound" />Swedish Vallhund

<option value = "Tibertan Mastiff" />Tibetan Mastiff

<option value = "Tibertan Spaniel" />Tibetan Spaniel

<option value = "Tibetan Terrier" />Tibetan Terrier

<option value = "Toy Fox Terrier" />Toy Fox Terrier

<option value = "Toy Manchester Terrier" />Toy Manchester Terrier

<option value = "Toy Poodle" />Toy Poodle

<option value = "Vizela" />Vizela

<option value = "Weimaraner" />Weimaraner

<option value = "Welsh Springer Spaniel" />Welsh Springer Spaniel

<option value = "Welsh Terrier" />Welsh Terrier

<option value = "West Highland White Terrier" />West Highland White Terrier

<option value = "Whippet" />Whippet

<option value = "Wire Fox Terrier" />Wire Fox Terrier

<option value = "Wirehaired Pointing Griffon" />Wirehaired Pointing Griffon

<option value = "Yorkshire Terrier" />Yorkshire Terrier

 

</td>

</select>

</tr>

<tr>

<td>Nutritional Needs:</td>

<td><textarea name="nutritionalNeeds" cols="17" rows="5"></textarea>

</td>

</tr>

<tr>

<td>Special Instructions</td>

<td><textarea name="specialInstructions" cols="17" rows="5"></textarea>

</tr>

<tr>

<td colspan = "6"><h2>Order Information</h2></td>

</tr>

<tr>

<td>Quanity:<input name="qty" type="text" size="2" maxlength="3" /></td>

<td>Treats: <select name = "treat"> <option selected value ="Please choose a treat"/>

Please choose a treat

<option value = "Wayah's Woofburgers and fries ($9.95/lb)"/>Wayah's Woofburgers and fries ($9.95/lb)

 

</select>

</tr>

<tr>

<td> <input name="Submit" type="button" value="Order Treats!" /></td><td><input name="reset" type="button" value="Cancel Order" /> </td>

</tr>

HEREDOC;

?>

</table>

</form>

<div id = "footer">

Auntie Vic's Treatery <br />

PO Box 34092 <br />

Clermont, IN 46234<br />

317-701-0343 <br />

<a href="mailto:auntievics@gmail.com">Email Us</a>

</div>

</body>

</html>

Link to comment
Share on other sites

when I load cheekout.php I get shoppingCart Object ( [items:protected] => Array ( ) )

That indicates that you still have this code:

 

print_r($shopping_cart);
exit; 

somewhere on the page. I'd suggest closing and reopening that file, and doing a search if you have to.

 

not understanding why treats.php isn't directing items to checkout.php

There's nothing about this code:

 

<?php

session_name("treats");

session_start();

?>

that tells PHP where it redirects to. Without this code on the page, you won't have access to the items within the shopping cart (and it may clear/recreate the shopping cart, I'm not sure) but those lines simply set up the session. The session itself doesn't control where pages redirect to.

 

Where the page redirects to depends on your render_products_from_xml() function -- specifically, this line: "<a href="order.php?id='.$product->id.'">add to cart</a>":

 

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="order.php?id='.$product->id.'">add to cart</a>

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

';
echo $output;
}

Link to comment
Share on other sites

When I put print_r($shopping_cart);

exit;

checkour.php comes up with a blank webpage with no errors. It should display the items chosen from treats.php.

 

However, when I remove print_r($shopping_cart);

exit;

from checkOut.php I still get this.

Fatal error: Call to a member function getItems() on a non-object in D:\Hosting\5246561\html\checkOut.php on line 36

Link to comment
Share on other sites

it's giving me another error.

 

 

Fatal error: Call to a member function addItem() on a non-object in D:\Hosting\5246561\html\checkOut.php on line 19

 

 

<?php

require_once('functions.php')

?>

<!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>Untitled Document</title>

</head>

 

<body>

<?php

$shopping_cart = get_shopping_cart();

 

$product_id=$_REQUEST['id'];

 

if (product_exist($product_id))

{

$shopping_cart->addItem($product_id);

}

?>

<table class="shoppingCart">

<tr>

<th>

Produt ID

</th>

<th>

quantity

</th>

<th>

Amount

</th>

</tr>

<?php

$line_item_counter = 1;

foreach ($shopping_cart->getItems() as $product_id)

{

echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter);

$line_item_counter++;

}

 

function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)

{

$quantity = $shopping_cart->GetItemquantity ($product_id);

/*video 8

$amount = $shopping_cart->GetItemCost($product_id);

$unit_cost = get_item_cost($product_id); */

$output = '

<tr>

<td>

$product_id

</td>

<td>

$quantity

</td>

<td>

$ $amount

</td>

</tr>';

return $output;

}

?>

 

 

</table>

<?php

set_shopping_cart($shopping_cart);

?>

</body>

</html>

 

 

<?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 inval($this->item[$product_id]);

}

}

?>

Link to comment
Share on other sites

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">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">'>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:auntievics@gmail.com">Email Us</a></div>

</body>

</html>

 

 

checkout.php

<?php

SESSION_start();

require_once('functions.php')

?>

<!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>Untitled Document</title>

</head>

 

<body>

<?php

$shopping_cart = get_shopping_cart();

if (isset($_GET["id"]))

{

$product_id = htmlspecialchars($_GET["id"]);

}

 

if (product_exist($product_id))

{

$shopping_cart->addItem($product_id);

}

?>

<table class="shoppingCart">

<tr>

<th>

Produt ID

</th>

<th>

quantity

</th>

<th>

Amount

</th>

</tr>

<?php

$line_item_counter = 1;

foreach ($shopping_cart->getItems() as $product_id)

{

echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter);

$line_item_counter++;

}

 

function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)

{

$quantity = $shopping_cart->GetItemquantity ($product_id);

/*video 8

$amount = $shopping_cart->GetItemCost($product_id);

$unit_cost = get_item_cost($product_id); */

$output = '

<tr>

<td>

$product_id

</td>

<td>

$quantity

</td>

<td>

$ $amount

</td>

</tr>';

return $output;

}

?>

 

 

</table>

<?php

set_shopping_cart($shopping_cart);

?>

</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
Share on other sites

So, just to be clear, products are not showing up in the cart, but you are currently not getting any errors? That's a step in the right direction at least.

 

One thing to note -- as I said in a previous comment -- you have multiple misspellings of the word "quantity". Sometimes it's "quantity", sometimes it is "quanity", sometimes it's "Quuanity". I'm not necessarily sure that is your issue, but it's definitely something you need to fix one way or another.

 

I'd suggest zipping up your project and emailing it to me (ben [at] falkencreative.com). I'll take a look and see if I can provide feedback. It's way easier if I have the code in front of me and can do the debugging directly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...