Jump to content

mindapolis

Member
  • Posts

    30
  • Joined

  • Last visited

Posts posted by mindapolis

  1. could you help me figure why it’s not displaying the shipping and total amount. The values are always 0.

     

     

    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->items[$product_id] = 1;

    }

    public function GetItemCost($product_id)

    {

    $cost_string = get_item_cost($product_id);

    $cost_float = "$cost_string" + 0;

     

    return $cost_float * $this->GetItemQuantity($product_id);

    }

    public function getItems()

    {

    return array_keys($this->items);

    }

    public function GetItemQuantity($product_id)

    {

    return intval($this->items[$product_id]);

    }

    public function emptyCart()

    {

    $this->items = array();

    }

    public function GetSsalesTax()

    {

    $salesTax = .07;

    $subTotal=GetItemQuantity * $salesTax;

    return $subTotal;

    }

     

    public function GetShippingCost($quantity)

    {

    if ($quantity <=2)

    return 10.95;

    else

    return 0;

    }

    public function ShippingCost()

    {

    $total = 0;

    foreach($this->items as $product_id -> $quantity)

    $total = $total + $this->GetItemQuantity($product_id);

    return $total;

    }

    /* public function GetTotal()

    {

    $salesTax = .07;

    return $this->GetSubTotal() + $salesTax;

    }*/

    public function GetSubTotal()

    {

    $total = 0;

    foreach($this->items as $product_id => $quantity)

    $total = $total + $this->GetItemCost($product_id);

     

    return $total;

    }

    public function GetSalesTax($unit_cost, $quantity)

    {

    $salesTax = .07;

    return $unit_cost*$quantity*$salesTax;

    }

    public function GetTotal()

    {

    return $this->GetSubTotal() + $this->GetShippingCost();

    }

    }

     

    templates.php

    <?php

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

    {

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

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

    $unit_cost = get_item_cost($product_id);

     

    $shipping_amount = $shopping_cart->GetShippingCost($quantity);

    $salesTax = $shopping_cart->GetSalesTax($unit_cost, $quantity);

    $output = "

    <tr>

    <td>

    $product_id

    <br />

    Sales Tax: $salesTax

    </td>

    <td>

    $quantity

    </td>

    <td>

    </td>

    <td>

     

    $$amount

    </td>

    </tr>";

    return $output;

    }

    function render_shopping_cart_shipping_row(ShoppingCart $shopping_cart)

    {

    return "

    <tr>

    <td>

    </td>

    <td>

    Shipping:

    </td>

    <td>

    '$.$shopping_cart->GetShippingCost().'

    </td>

    </tr>

    ";

    }

    function render_shopping_cart_total_row(ShoppingCart $shopping_cart)

    {

    return "

    <tr>

    <td>

    </td>

    <td>

    Total:

    </td>

    <td>

    '.$shopping_cart->GetTotal().'

    </td>

    </tr>

    ";

    }

    /*video 11

    function render_paypal_checkout(ShoppingCart $shopping_cart)

    {

    return "

    <form action='".PAYPAL_FORM_URL."' method='post'>

    <input type="hidden" name="business" value=" " />

    <input type="hidden" name="cmd" value="_cart" />

    <input type="hidden" name="upload" value="1" />

    <input type="hidden" name="currency_code" value="USD" />

    <input type="hidden" name="LC" value="US" />

     

    " . render_shopping_cart($shopping_cart) ."

    <input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' alt=' pay online with PayPal '>

     

    </form>";

    }

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

    <input type="hidden" name="cmd" value="_s-xclick">

    <input type="hidden" name="hosted_button_id" value="M8GEXMCBNPSPC">

    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">

    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

    </form>*/

     

    ?>

     

    checkout.php

    <?php

    require_once('functions.php');

    require_once('templates.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>

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

    <style type="text/css">

    .shoppingCart {

    width: 600px;

    margin: 0;

    }

    </style>

    </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>

    Product 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++;

    }

     

    echo render_shopping_cart_shipping_row($shopping_cart);

    echo render_shopping_cart_total_row($shopping_cart);

     

     

    ?>

    </table>

    <?php

    set_shopping_cart($shopping_cart);

    ?>

     

    </body>

    </html>

  2. I hesitated posting this because most of my errors are stupid mistakes on my end. however, I'm doing the shopping cart video series and I'm stuck at the very end of video 8. I have watched it three or four times and for some reason the quantity isn't matching up with the price. here's the code:

     

    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->items[$product_id] = 1;

    }

    public function GetItemCost($product_id)

    {

    $cost_string = get_item_cost($product_id);

    $cost_float = "$cost_string" + 0;

     

    return $cost_float * $this->GetItemQuantity[$product_id];

    }

    public function getItems()

    {

    return array_keys($this->items);

    }

    public function GetItemQuantity($product_id)

    {

    return intval($this->items[$product_id]);

    }

    public function emptyCart()

    {

    $this->items = array();

    }

    }

     

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

    '.$product->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;

    }

    function get_item_cost($product_id)

    {

    foreach(get_xml_catalog() as $product)

    {

    if ($product_id == $product->id)

    return $product->price;

    }

    throw new Exception('item not found' . $product_id);

    }

    ?>

     

    checkout.php

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

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

    {

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

    }

     

    if (product_exist($product_id))

    {

    $shopping_cart->addItem($product_id);

    }

    ?>

    <table class="shoppingCart">

    <tr>

    <th>

    Product 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);

    $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>

  3. 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);

    }

    ?>

  4. 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]);

    }

    }

    ?>

  5. 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

  6. 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>

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

    }

    ?>

  8. now it says

     

    Warning: Unexpected character in input: ''' (ASCII=39) state=1 in D:\Hosting\5246561\html\classes\shoppingCart.php on line 19

    shoppingCart Object ( [items:protected] => Array ( ) )

  9. 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>

    '

  10. 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>

  11. Okay, I figured out one error, but am stuck on another one.

     

    Warning: unserialize() expects parameter 1 to be string, object given in D:\Hosting\5246561\html\functions.php on line 24

     

    <?php

    require_once('classes/shoppingCart.php');

    /**DEFINE GLOBALS**/

    define('STORE_XML_FILE' , 'catalog.xml');

     

    /*FUNCTIONS*/

    session_start();

    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'] = unserialize($cart);

    }

     

    function product_exist($product_id)

    {

    foreach(get_xml_catalog() as $product)

    {

    if ($product->id = $product_id)

    return true;

    }

    return false;

    }

    ?>

  12. That didn't help. Here's the revised code.

     

    <?php

    class shoppingCart {

    protected $items = array();

    public function addItem($product_id)

    {

    if (array_key_exists($product_id , $this->item))

    $this->item[$product_id] = $this->item[$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];

    }

    }

    ?>

  13. didn't help

     

    the error is on checkOut.php

     

    functions.php

    <?php

    require_once('classes/shoppingCart.php');

    /**DEFINE GLOBALS**/

    define('STORE_XML_FILE' , 'catalog.xml');

     

    /*FUNCTIONS*/

    session_start();

    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'] = unserialize($cart);

    }

     

    function product_exist($product_id)

    {

    foreach(get_xml_catalog() as $product)

    {

    if ($product->id = $product_id)

    return true;

    }

    return false;

    }

    ?>

     

    checkout.php

    <?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_exists($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(shopping_cart $shopping_cart, $product_id , $line_item_counter)

    {

    $quanity = $shopping_cart->GetItemQuuanity(#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>

  14. Why am I getting this error?

     

     

    Fatal error: Class 'ShoppingCart' not found in D:\Hosting\5246561\html\functions.php on line 17

     

    functions.php

    <?php

    require_once('classes/shoppingCart.php');

    /**DEFINE GLOBALS**/

    define('STORE_XML_FILE' , 'catalog.xml');

     

    /*FUNCTIONS*/

     

    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'] = unserialize($cart);

    }

     

    function product_exist($product_id)

    {

    foreach(get_xml_catalog() as $product)

    {

    if ($product->id = $product_id)

    return true;

    }

    return false;

    }

    ?>

     

    shoppingCart.php in the class folder which is uploaded

     

    <?php

    class shoppingCart {

    protected $items = array();

    public function addItem($product_id)

    {

    if (array_key_exists($product_id . $this->item))

    $this->item[$product_id] = $this->item[$product_id] +1;

    else

    $this->item[$product_id] = 1;

    }

    public function getItems()

    {

    return array_keys($this->item);

    }

    }

    ?>

  15. still not working

     

    error

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/Chu'>http://auntievics.com/assets/Chu'>http://auntievics.com/assets/Chu in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 16: parser error : attributes construct error in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/Chu in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 16: parser error : Couldn't find end of Start Tag img line 16 in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/Chu in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 19: parser error : XML declaration allowed only at the start of the document in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <?xml version="1.0" encoding="utf-8"?> in D:\Hosting\5246561\html\functions.php on line 9

     

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in D:\Hosting\5246561\html\functions.php on line 9

     

    Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\Hosting\5246561\html\functions.php:9 Stack trace: #0 D:\Hosting\5246561\html\functions.php(9): SimpleXMLElement->__construct('<?xml version="...') #1 D:\Hosting\5246561\html\treats.php(73): get_xml_catalog() #2 {main} thrown in D:\Hosting\5246561\html\functions.php on line 9

     

    <?xml version="1.0" encoding="utf-8"?>

    <item>

    <product>

    <id>WoofburgersAndFries </id>

    <title> Wayah's Woofburgers and fries</title>

    <description> Burger: Unbleached and rye flours, cheddar cheese, unsalter butter, beef broth, cornmeal, canola oil, garlic powder, seseme seeds, egg whites, beet and spinach powders.

    <br />

    Fries: Unbleached flour, cheddar cheese, chicken broth, garlic powder </description>

    <img alt = "Woof burgers and fries" src="http://auntievics.com/assets/WayahsWoofburgers.jpg"'>http://auntievics.com/assets/WayahsWoofburgers.jpg" />

    <price> $9.95/lb</price>

    </product>

    <product>

    <id> BoChunkyPeanutButterChunchies </id>

    <title>Bo's Chunky Peanut Butter Chunchies </title>

    <description>Whole wheat flour, wheat germ, crunchy peanut butter, distilled water, rolled oats canola oil, eggs </description>

    <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg"'>http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" />

    <price> $9.95 </price>

    </product>

    <?xml version="1.0" encoding="utf-8"?>

    <item>

    <product>

    <id>WoofburgersAndFries </id>

    <title> Wayah's Woofburgers and fries</title>

    <description> Burger: Unbleached and rye flours, cheddar cheese, unsalter butter, beef broth, cornmeal, canola oil, garlic powder, seseme seeds, egg whites, beet and spinach powders.

    <br />

    Fries: Unbleached flour, cheddar cheese, chicken broth, garlic powder </description>

    <img> http://auntievics.com/assets/WayahsWoofburgers.jpg </img>

    <price> $9.95/lb</price>

    </product>

    <product>

    <id> BoChunkyPeanutButterChunchies </id>

    <title>Bo's Chunky Peanut Butter Chunchies </title>

    <description>Whole wheat flour, wheat germ, crunchy peanut butter, distilled water, rolled oats canola oil, eggs </description>

    <img>http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg </img>

    <price> $9.95 </price>

    </product>

     

    </item>

×
×
  • Create New...