I have a couple of input boxes where the user will be entering his/her data .
for example:

Fathers name:-----------
mothers name:------------

when the user enters the data , i need the xml to be generated something like this

<name> users name </name>
<fname> fathers name </fname>
<mname> mothers name </mname>

7 Years
Discussion Span
Last Post by rahul8590

You need to have a HTML form to 'POST' (Submit) the form and a PHP script to generate the file.
The HTML side
call this form.html or something

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form Page</title>

<form name="form1" action="generate.php" method="post">
Name: <input name="name" type="text" /><br/>
Mothers Name: <input name="mname" type="text" /><br/>
Fathers Name: <input name="fname" type="text" /><br/>
<input name="submit" type="submit" value="Submit" />

Then the PHP code to generate the XML
call this generate.php (As per our action in the HTML form)

header('Content-type: text/xml');//Tell the browser it's an XML document
echo '<?xml version="1.0"?'.'>'."\n";//We have to break up the XML closing tag because [?]> is the closing tag for PHP
echo "<family>

that was great .. it really helped me . but supposedly the input is dynamic in nature . i mean if i dont know the number of name inputs , in that case how do i generate the xml data out of it.


here is a basic example of wat i meant by dynamic
the below is a basic form meant ti generate the no of name fields as inputed

<form action="redirect_new.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
$val = $_POST['yourname'];

for ( $i = 1; $i <= $val ; $i++)
<form action="redirect1.php" method="post">
Name: <?php echo $i ?>  <input type="text" name=<?php echo "\"yourname"."$i\""   ?> maxlength="150" /><br />

<input type="submit" value="Submit" style="margin-top: 10px;" />

the above is the equivalent php code . Now in this case since we dont know the number of name fields to be entered , how do i generate the xml data for this ?


firstly srry for late reply , for some reason i aint getting notification of reply for the threads i started in daniweb , dunno y.

that is an awesome link .. very helpful .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.