PHP creating XML output problem

James you are a LEGEND!!! Works perfectly - I have completed the script and added it below should anyone come across a similar issue:

[php]<?php
//set the content type to XML
header(“Content-type: text/xml”);
//initialise the xmlBody variable
$xmlBody = ‘<?xml version="1.0" encoding="ISO-8859-1"?>’;
//start XMLBody output
$xmlBody .= “”;

//define the variables to be received from user input
$artist =$_POST[‘artist’];
$medium =$_POST[‘medium’];
$size =$_POST[‘size’];
$format =$_POST[‘format’];
$subject =$_POST[‘subject’];
$colour =$_POST[‘colour’];
$price =$_POST[‘price’];
$available =$_POST[‘available’];

//define database connection variables
$host = “127.0.0.1”;
$user = “root”;
$pass = “”;
$database = “syntegallery”;

//connect to the database and define its name
$con = mysql_connect($host, $user, $pass) or die (mysql_error());
mysql_select_db($database, $con) or die (“Could not find database”);

//define the mysql query
$result = mysql_query("SELECT Filename, Thumbnail, Empirical FROM gallery WHERE Artist=’$artist’ AND Medium=’$medium’ AND Category=’$size’ AND Format=’$format’ AND Subject=’$subject’ AND Colour=’$colour’ AND Range=’$price’ AND Available=’$available’ ", $con) or die (“Data not found”);

//create incremental counter
$i = 0;

//create while loop to search until all rows have been checked against query and define XML structure
while($row = mysql_fetch_array($result))
{
$Filename = $row[“Filename”];
$Thumbnail = $row[“Thumbnail”];
$Empirical = $row[“Empirical”];
$i++;
$xmlBody .= ’

‘.$Filename.’
‘.$Thumbnail.’
‘.$Empirical.’
';
}//end the while loop

//end XmlBody output
$xmlBody .= “”;
//print xmlBody to be parsed and displayed to user
print $xmlBody;
//close mysql connection
mysql_close($con);
exit();
?>[/php]

Thanks again James for your patience and advice - you saved me from certain insanity!

Sponsor our Newsletter | Privacy Policy | Terms of Service