Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

XML Parsing Error: junk after document element? Please help.

$
0
0

Hello,

 

I have a PHP file that will show some products from Mysql database. this works without any issue.

But I need to create an XML file from this PHP file in order to be able to load it into flash.

I have done the most part and the PHP file creates an XML file on the server and pulls the data (only text format data, i.e. product name, price, details, date added etc etc) and it works perfectly fine BUT, i don't know what to do for the images part!!

This is the original PHP file:

 

<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
// Run a select query to get my letest 6 items
// Connect to the MySQL database 
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td>
<td width="83%" valign="top">' . $product_name . '<br />
. $price . '<br />
<a href="product.php?id=' . $id . '">View Product Details</a></td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
 

and this is the PHP file that creates the XML file:

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "../config/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){
             $id = $row["id"];
             $product_name = $row["product_name"];
             $price = $row["price"];
             $image = $row["<a href='../product.php?id=" . $id . "'><img src='../inventory_images/" . $id . ".jpg' alt='" . $product_name . "'/></a>"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
    $xmlBody .= '
<Data>
    <DataID>' . $id . '</DataID>
    <DataTitle>' . $product_name . '</DataTitle>
    <DataDate>' . $price . '</DataDate>
    <DataImage>' . $image . '</DataImage>
    <DataDescr>' . $date_added . '</DataDescr>
</Data>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
}
?>
<?php echo $dynamicList; ?>

 

by running the code above, I am keep getting this error:

 

XML Parsing Error: junk after document element
Location: test.php
Line Number 2, Column 1:

<b>Notice</b>:  Undefined index: <a href='../product.php?id=127'><img src='../inventory_images/127.jpg' alt='Example 1'/></a> in <b>test.php</b> on line <b>21</b><br />
^

 

Could someone please help! I am lost!!


Viewing all articles
Browse latest Browse all 13200

Trending Articles