Topic: Shopping cart tutorial

Hey all, I have been trying to do the Shopping cart tutorial and have gotten to a point where its not working how it says it should in the video.  below i've posted the code that i've used so if someone can tell me what i'm doing wrong that would be great.
thanks in advance

index.php

<?php
    require_once '../functions/functions.php'
   
    $xml = new SimpleXMLElement(file_get_contents(STORE_XML_FILE));
   
    foreach($xml as $product)
    {
        echo "<li>$product->title</li>";
    }
?>

catalog.xml

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <product>
        <id>TOMATOSOUP</id>
        <title>Tomato Soup</title>
        <description> Freshly-made Tomato Soup in a can</description>
        <img>http://www.ayushveda.com/dietfitness/wp-content/uploads/2008/07/tomatosoup.jpg</img>
        <price>1.33</price>
    </product>
    <product>
        <id>PASTA</id>
        <title>Linguini</title>
        <description>real authentic lunguini</description>
        <img>http://www.cookworm.com/images/linguini-chickpeas-lemon02.jpg</img>
        <price>2.55</price>
    </product>

functions.php

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




?>

Its just displaying a blank screen instead of the <li> items

Vote up Vote down

Re: Shopping cart tutorial

I haven't done the videos myself, so I can't really comment too much...

However, my guess is that the "catalog.xml" file could be in the wrong location, so PHP can't find it. Double check that the file is in the correct location... according to your code, it should be one folder up from the index.php file. If you have the index.php file and the catalog.xml file in the same folder, I believe you would need to remove the "../" from the STORE_XML_FILE constant.

However, before you check that, double check that your "catalog.xml" file has a closing </items> at the end of the file. Your example above didn't include that, so I'm not sure if it is missing or you just forgot to copy that bit. Might be causing an issue.

Benjamin Falk | Falken Creative : Twitter
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter

Vote up Vote down

Re: Shopping cart tutorial

also in the index file you have:

require_once '../functions/functions.php'

this suggests that your main site index.php is in a sub directory with catalogue.xml is in the root and functions.php is in the functions/ sub directory.

i would suggest that you have index.php in the root, leave functions where it is.

then in index.php change:

require_once '../functions/functions.php'

to:

require_once 'functions/functions.php'

make sure that catalogue.xml is in the root as this where functions.php is looking for it.

Vote up Vote down