retrodog
03-06-2005, 09:42 PM
I have a form that submits captions via textboxes to a php page that gets written to an child node in an XML file. I am using a while loop since there are up to 35 caption textboxes into which a user can input data. I have tried everything to try to get the data into the XML, namely by using a while loop to get the $caption$i=$_POST['caption$i'] value.
The XML is written correctly when I use $caption1 instead '$caption$i' below so I know the data is being passed to the next page correctly. When I use '$caption$i' only 1, 2, 3, etc gets written to the string. When I use "$caption$i", then $caption$i gets written. SOMEONE PLEASE HELP! HOW CAN I GET THIS DATA TO DISPLAY CORRECTLY?
$doc = new_xmldoc('1.0');
$root = $doc->add_root('gallery');
$root->set_attribute('galleryname',"");
$root->set_attribute('layout',"2");
$i=1;
while ($i<$count)
{
$image = $root->new_child('image',"images/$i.jpg");
$image->set_attribute('thumb',"images/thumb_$i.jpg");
$captiontext = $root->new_child('captiontext', '$caption$i');
$i++;
}
// set output filename
$filename= "../../Clients/$firstname$lastname/gallery.xml";
$fp = @fopen($filename,'w');
if(!$fp) {
die('Error cannot create XML file');
}
fwrite($fp,$doc->dumpmem());
fclose($fp);
?>
The XML is written correctly when I use $caption1 instead '$caption$i' below so I know the data is being passed to the next page correctly. When I use '$caption$i' only 1, 2, 3, etc gets written to the string. When I use "$caption$i", then $caption$i gets written. SOMEONE PLEASE HELP! HOW CAN I GET THIS DATA TO DISPLAY CORRECTLY?
$doc = new_xmldoc('1.0');
$root = $doc->add_root('gallery');
$root->set_attribute('galleryname',"");
$root->set_attribute('layout',"2");
$i=1;
while ($i<$count)
{
$image = $root->new_child('image',"images/$i.jpg");
$image->set_attribute('thumb',"images/thumb_$i.jpg");
$captiontext = $root->new_child('captiontext', '$caption$i');
$i++;
}
// set output filename
$filename= "../../Clients/$firstname$lastname/gallery.xml";
$fp = @fopen($filename,'w');
if(!$fp) {
die('Error cannot create XML file');
}
fwrite($fp,$doc->dumpmem());
fclose($fp);
?>