im trying to create a xml file using php.everytime i run the code the page displayes the code from a certain point as text on the screen.the code i hav is as follows:
<?php
if(!$dbconnet = mysql_connect('I took out the details')){
echo "connection failed to the host.";
exit;
}
if (!mysql_select_db('siamsati_db')){
echo "Cannot connect to the database.";
exit;
}
$table_id = 'events';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query, $dbconnect);
$doc = new DomDocument('1.0');
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
while($row = mysql_fetch_assoc($dbresult)){
$ooc = $doc->createElement($table_id);
$occ = $root->appendChild($occ);
foreach ( $row as $fieldname => $fieldvalue){
$child = $doc->createElement($fieldname);
$child = $occ->appendchild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
$xml_string = $doc->saveXML();
echo $xml_string;
?>
and the page when displayed shows:
createElement('root'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($dbresult)){ $ooc = $doc->createElement($table_id); $occ = $root->appendChild($occ); foreach ( $row as $fieldname => $fieldvalue){ $child = $doc->createElement($fieldname); $child = $occ->appendchild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } $xml_string = $doc->saveXML(); echo $xml_string; ?>
is there something ive missed.ive checked all the quotes thinking it was that at first but they all seem to be right.any suggestions on what im doing wrong are much appreciated?
?
before the>
in the line that reads$root = $doc->createElement('root');
? That would make the PHP interpreter switch to HTML mode and dump everything that follows giving the output you posted. At least I cannot imagine you compiled PHP with->
as the closing tag. That'd be totally sick. – rik Mar 15 '11 at 14:39