PHP creating XML output problem
Posted: Wed Dec 21, 2011 9:07 am
Hi everyone,
would it be possible please to have a look at the below PHP - it is receiving 8 variables but I receive an error saying that the file must be "well formed" and "only one top level element is allowed in an XML document". Any ideas as to what the problem could be?
Thanks so much!
would it be possible please to have a look at the below PHP - it is receiving 8 variables but I receive an error saying that the file must be "well formed" and "only one top level element is allowed in an XML document". Any ideas as to what the problem could be?
Code: Select all
<?php
header("Content-type: text/xml");
$artist =$_POST['artist'];
$medium =$_POST['medium'];
$size =$_POST['size'];
$format =$_POST['format'];
$subject =$_POST['subject'];
$colour =$_POST['colour'];
$price =$POST['price'];
$available =$POST['available'];
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
$host = "127.0.0.1";
$user = "root";
$pass = "";
$database = "syntegallery";
$con = mysql_connect($host, $user, $pass) or die (mysql_error());
mysql_select_db($database, $con) or die ("Could not find database");
$query = "SELECT Filename, Thumbnail, Empirical";
$query .= "FROM gallery";
$query .= "WHERE Artist='$artist'";
$query .= "AND Medium='$medium'";
$query .= "AND Category='$size'";
$query .= "AND Format='$format'";
$query .= "AND Subject='$subject'";
$query .= "AND Colour='$colour'";
$query .= "AND Range='$price'";
$query .= "AND Available='$available'";
$query .= "ORDER BY Empirical";
$result = mysql_query($query, $con) or die ("Data not found");
$index = 0;
while($row = mysql_fetch_array($result))
{
$Filename = $row["Filename"];
$Thumbnail = $row["Thumbnail"];
$Empirical = $row["Empirical"];
$index++;
$xmlBody .= '
<gallery>
<filename>'.$Filename.'</filename>
<thumbnail>'.$Thumbnail.'</thumbnail>
<empirical>'.$Empirical.'</empirical>
</gallery>';
}
$xmlBody .= "</XML>";
print $xmlBody;
mysql_close($con);
exit();
?>