mindapolis Posted August 3, 2011 Report Posted August 3, 2011 Hi, I'm doing the shopping cart video series and I can't get the product image to show up. here is the xml file <?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>
newseed Posted August 3, 2011 Report Posted August 3, 2011 (edited) Incorrect use of the image tag: <img>"http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" </img> The correct way: <img alt="alternative text here" src="http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg"> Edited August 3, 2011 by Eddie
falkencreative Posted August 3, 2011 Report Posted August 3, 2011 @Eddie - Mindapolis is dealing with XML, not HTML, so I don't believe your solution above will work. @Mindapolis - Perhaps you can share the PHP code that uses the image path from the XML file? I believe that is the render_products() function within templates.php. I'm not seeing an error within the XML file.
mindapolis Posted August 3, 2011 Author Report Posted August 3, 2011 <?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 $output = '.<table class="product"> <tr>'; foreach(get_xml_catalog() as $product) { $output .=' <td class="product"> <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>
falkencreative Posted August 3, 2011 Report Posted August 3, 2011 This line is incorrect: <img src="'.$product->img.' height="" Width="" /> it should be: <img src="'.$product->img.'" height="" Width="" /> (missing a quotation mark to close of the src="" portion. Also, if you are not going to set the image's height/width, I would remove that from the <img /> tag.
mindapolis Posted August 3, 2011 Author Report Posted August 3, 2011 I'm getting this error now. Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 9: parser error : attributes construct error in D:\Hosting\5246561\html\functions.php on line 9 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <img alt = "Woof burgers and fries src="http://auntievics.com/assets/WayahsWoo'>http://auntievics.com/assets/WayahsWoo 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 9: parser error : Couldn't find end of Start Tag img line 9 in D:\Hosting\5246561\html\functions.php on line 9 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <img alt = "Woof burgers and fries src="http://auntievics.com/assets/WayahsWoo 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 here is the code again. <?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 $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; ?> </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>
falkencreative Posted August 3, 2011 Report Posted August 3, 2011 This line is incorrect: <img src=".$product->img"> it needs to be: <img src="'.$product->img . '" /> the single quote after the double quote closes the string, the period concatinates (adds) $product->img to the string, and the period/single quote at the end continues the string. Also, since you are using XHTML rather than HTML, you need to close the img tag with a "/>".
mindapolis Posted August 4, 2011 Author Report Posted August 4, 2011 It's still giving me that error after I put <img src="'.$product->img. '" />
falkencreative Posted August 4, 2011 Report Posted August 4, 2011 Have you made any changes to the XML file since you posted the code originally? The error message seems to indicate that there is an error in the XML file, on/near this line: <img>http://auntievics.com/assets/WayahsWoofburgers.jpg</img> specifically involving a missing/incorrect </img> tag. Other than that, I'm seeing one potential issue: <img>"http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" </img> needs to be (no quotes) <img>http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg</img> I don't think that is causing the error, but it is still something I would fix.
mindapolis Posted August 4, 2011 Author Report Posted August 4, 2011 Here the xml file again <?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" /> <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" /> <price> $9.95 </price> </product> </item>
falkencreative Posted August 4, 2011 Report Posted August 4, 2011 These two lines need to go back to the way they were before: <img alt = "Woof burgers and fries" src="http://auntievics.com/assets/WayahsWoofburgers.jpg" /> <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" /> I tried to indicate that Eddie's solution above was incorrect, but you must have missed it. You are dealing with XML, not HTML, so you need to go back to the previous version: <img>http://auntievics.com/assets/WayahsWoofburgers.jpg</img> and <img>http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg</img>
mindapolis Posted August 4, 2011 Author Report Posted August 4, 2011 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>
falkencreative Posted August 4, 2011 Report Posted August 4, 2011 Looks like you've doubled the xml file somehow? Note the two <?xml version="1.0" encoding="utf-8"?> tags? I think you must have accidentally pasted the code twice within the XML file. You'll need to fix that, and that will take care of half of the errors. The other error you are running into is from this line: <img alt "Bo's Peanut Butter Chunchies" src= "http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg" /> as I said above, it needs to be <img>http://auntievics.com/assets/ChunckyPeamuttButterCrunchies.jpg</img>
Recommended Posts