Jump to content

struggling with this code


mindapolis

Recommended Posts

Could someone please help me figure out this error. 

 

Warning: file_get_contents(STORE_XML_FILES) [function.file-get-contents]: failed to open stream: No such file or directory 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('') #1 D:\Hosting\5246561\html\treats.php(54): get_xml_catalog() #2 {main} thrown in D:\Hosting\5246561\html\functions.php on line 9

 

Here’s the code for the product  page. 

<code>

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

.description {

                width: 200px;

                padding-left: 5px;

}

.price {

                font-weight: bold;

}

 

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

<?php

require_once 'functions.php';

 

foreach(get_xml_catalog() as $product)

{

                echo '<li>$product->title</li>';

}

?>

</body>

</html>

</code>

 

Functions file

<code>

<?php

/**DEFINE GLOBALS**/

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

 

/*FUNCTIONS*/

 

function get_xml_catalog()

{

return new SimpleXMLElement(file_get_contents(STORE_XML_FILES));

}

?>

</code>

 

Catalog.xml file

<code>

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

<item> 

                <product>

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

</item>

</code>

Link to comment
Share on other sites

I need a second pair of eyes.  Why am I getting this error? 

Fatal error: Call to undefined function get_xml_catalog() in D:\Hosting\5246561\html\treats.php

 

<code>

<?php

/**DEFINE GLOBALS**/

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

 

/*FUNCTIONS*/

 

function get_xml_catalog()

{

return new SimpleXMLElement(file_get_contents(STORE_XML_FILE));

}

?>

<code>

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

#mainContent {

margin: 0 auto;

text-align:center;

width:600px;

}

.description {

width: 200px;

padding-left: 5px;

}

.price {

font-weight: bold;

}

 

#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

$output = '.<table class="product">

<tr>';

foreach(get_xml_catalog() as $product)

    {

    $output .='

<td>

<h2>'.$product->title.'</h2>

<div>

<img src="'.$product->img.' height="" Width="" />

<span>

'.$product->description.'

</span>

</div>

<div class="price">

'.$price->price.'

</div>

<div class="addToCart">

<a href="#">add to cart</a>

 

</div>

</td>';

    }

$output .='

</tr>

</table>

';

echo $output;

?>

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

 

Link to comment
Share on other sites

didn't see that button, sorry! ! 

 

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

/*FUNCTIONS*/

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

 

<?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">
#mainContent {
   margin: 0 auto;
   text-align:center;
   width:600px;
   }
.description {
   width: 200px;
   padding-left: 5px;
}
.price {
   font-weight: bold;
}

#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
$output = '.<table class="product">
         <tr>';
foreach(get_xml_catalog() as $product)
    {
    $output .='
      <td>
               <h2>'.$product->title.'</h2>
               <div>
                  <img src="'.$product->img.' height="" Width="" />
                  <span>
                     '.$product->description.'
                  </span>
               </div>
               <div class="price">
                  '.$price->price.'
               </div>
               <div class="addToCart">
                  <a href="#">add to cart</a>
                  
               </div>
               </td>';
    }
   $output .='
      </tr>
   </table>
   ';
echo $output;
?>
</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>

Link to comment
Share on other sites

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

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

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