PHP and XML
Posted: Thu Jun 25, 2009 6:46 pm
I'm trying to Write a XML file with PHP The Code I have is
The Data come out correctly but i get the Error "Only one top level element is allowed in an XML document. Error processing resource" and "Only one top level element is allowed in an XML document. Error processing resource"
Can anyone help!
Thanks Guys
Code: Select all
<?php
header("Content-type: text/xml");
$myServer = "MYSERVER\SQLEXPRESS";
$myUser = "sa";
$myPass = "MYPW";
$myDB = "cars";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT id, type, year ";
$query .= "FROM cars";
//execute the SQL query and return records
$result = mssql_query($query);
//display the results
while($row = mssql_fetch_array($result))
{
$yearrow = $row['year'];
$typerow = $row['type'];
echo "<note>";
echo "<from>$yearrow</from>";
echo "<to>$typerow</to>";
echo "</note>";
}
//close the connection
mssql_close($dbhandle);
?>
Can anyone help!
Thanks Guys