![]() |
How to use form data to create XML???
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); ?> |
Perhaps the problem lies in the assignment of $_POST['caption$i'] to $caption$i in your code. Use error_reporting(E_ALL); and see what shows onscreen, and maybe consider using $caption[$i] = $_POST['caption$i']; and $captiontext = $root->new_child('captiontext', '$caption[$i]'); instead.
|
All times are GMT -8. The time now is 11:36 AM. |
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.