Forum Moderators: coopster

Message Too Old, No Replies

xml generating using a form and php

         

anfetienne

9:59 pm on Mar 13, 2009 (gmt 0)

10+ Year Member



Hi,

I have created this code to get data from a html form into php and then generate an xml file. I am having a problem looping....I need it to loop so that if there is more than one caption that has been submitted then a new line of xml will start with the corresponding data. Each loop i have tried has given me an error saying the header has already been sent.

Here is my code......thanks in advance

<?php

if(isset($_POST['create_xml'])){

$picT = $_POST['picT'];

$photoT = $_POST['photoT'];

$captionT = $_POST['captionT'];

$xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gallery></gallery>";
$xmlobj = simplexml_load_string($xmltext);

$nameCapsA = $xmlobj->addChild("$picT");
$nameCapsA->addAttribute("name", "$photoT");
$nameCapsA->addAttribute("caption", "$captionT");

// set output filename
$filename= "test1.xml";

print header("Content-type: text/plain") . $xmlobj->asXML();
}

?>

IanKelley

7:08 pm on Mar 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Out your header --> header("Content-type: text/plain") <-- somewhere earlier in the script, before you run the loop.