Current location: Hot Scripts Forums » Programming Languages » PHP » Mysql to write xml


Mysql to write xml

Reply
  #11 (permalink)  
Old 05-12-09, 05:04 PM
dgreenhouse's Avatar
dgreenhouse dgreenhouse is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: San Francisco
Posts: 457
Thanks: 0
Thanked 3 Times in 3 Posts
Slight mistake...

As far as the custom temporary variables' table is concerned, you can use a generated session id
versus using the form_id and ip address - which wouldn't work properly anyway in this situation.

This session id is added as a hidden form element to each pages' form and will have to be generated for the first page of the multi-page forms. This is of course for the case where you've detected that the visitor doesn't have cookies enabled (if you want to include those visitors).

So... This table would be structured like:
session_id (char(40)), form_id (varchar(16)), variables (blob).

You could still add the IP address if you like for minimal assurance that the form hasn't been hi-jacked.

For additional security, you'd need to add a unique id to each form that gets generated each time.
(You'll of course need an additional table to store the token values)

So for a more full form structure:
Code:
<form action="" method="post">
  <input type="hidden" name="sid" value="seesion_id_generated_value_here" />
  <input type="hidden" name="tkn" value="unique_token_generated_value_here" />
  <input type="text" name="var1" />
  <input type="text" name="var2" />
  <input type="checkbox" name="var3" />
  <input type="submit" name="submit" value="Click Me!" />
</form>

Last edited by dgreenhouse; 05-12-09 at 05:07 PM.
Reply With Quote
  #12 (permalink)  
Old 05-16-09, 04:10 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
page 1................................................. ..............

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Welcome to the World of&nbsp; babies</title>
</head>

<body>
<form method="POST" action="Page2.php" name="B1">

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<marquee></marquee>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;
<font color="#FF6666">&nbsp;<font face="Algerian" size="6">Welcome to the World
of&nbsp; babies</font></font></p>
<p>&nbsp;</p>
<p><font size="4" color="#008000">Enter Your Full Name --</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="Fullname" size="20"></p>
<p><font size="4" color="#008000">Annual Income in thousands --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;
</font><input type="text" name="Income" size="20"></p>
<p><font size="4" color="#008000"><font face="Times New Roman">Address --</font><font face="Arial">&nbsp;
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
</font><input type="text" name="Address" size="20"></p>
<p><font size="4" color="#008000">City -- </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;
<input type="text" name="City" size="20"></p>
<p><font size="4" color="#008000">State --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><input type="text" name="State" size="20"></p>
<p><font color="#008000" size="4">Contact Number--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;
</font><input type="text" name="Contactnumber" size="20"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp; </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;
<b>
<input type="submit" value="Submit" onClick="page2.php" name="B1" style="font-family: Times New Roman; font-weight: bold; font-size: 12pt"></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><input type="reset" value="Clear" name="B2" style="font-family: Times New Roman; font-size: 12pt; font-weight: bold"></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
</form>
<b><form method="POST" action="Page2.php" name="32">
&nbsp;</form>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>

</body>

</html>

.................................................. ...page 2................................................. .

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>We Need Some More Information So That We Can Help You Better</title>
</head>

<body>
<form method="POST" action="Page3.php" name="B1">
<p><font size="5" face="Algerian" color="#800000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
We Need Some More Information So That We Can Help You Better...</font></p>
<p>&nbsp;</p>
<p><font face="Times New Roman" size="4" color="#008000">Message--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><input type="text" name="Message" size="20"></p>
<p><font color="#008000"><font size="4">Are You Married? Give details --&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></font><input type="text" name="Status" size="20"><font color="#008000">
</font></p>
<p><font size="4" color="#008000">Criminal Record -- </font><font size="4">&nbsp;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="Crecord" size="20"></p>
<p><font size="4" color="#008000">Reason To Adopt--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font><input type="text" name="Reson" size="20"></p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;
<input type="submit" value="Submit" onClick="page3.php" name="B1" style="font-family: Times New Roman; font-weight: bold; font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Clear" name="B2" style="font-family: Times New Roman; font-size: 12pt; font-weight: bold"></p>
<p>&nbsp;</p>
</form>
<b><form method="POST" action="Page3.php" name="32">
<?
$a1=$_POST['Fullname'];
$a2=$_POST['Income'];
$a3=$_POST['Address'];
$a4=$_POST['City'];
$a5=$_POST['State'];
$a6=$_POST['Contactnumber'];




$con=mysql_connect('localhost','root','password') or die('ERROR');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE adoption",$con))
{
echo "Database created";
mysql_select_db("adoption",$con);
}

mysql_select_db("adoption",$con);

if (mysql_query("CREATE TABLE information(Fullname varchar(30),Income int(30),Address varchar(30),
City varchar(20),State varchar(20),Contactnumber int(12)",$con))
{
echo "Table created";
}

$p="insert into information(Fullname,Income,Address,City,State,Con tactnumber)values
('$a1','$a2','$a3','$a4','$a5','$a6')";
mysql_query($p);
?>

</body>

</html>
.................................................. ...........page 3................................................. .......

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/xml; charset=windows-1252">
<title>Thanks For Your Valuable Time We Will Get Back To You Within Next 48 Hrs
</title>
</head>
<body>
<?
$a7=$_POST['Message'];
$a8=$_POST['Status'];
$a9=$_POST['Crecord'];
$a10=$_POST['Reson'];


$con=mysql_connect('localhost','root','password') or die('ERROR');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE adoption",$con))
{
echo "Database created";
mysql_select_db("adoption",$con);
}
else
mysql_select_db("adoption",$con);

if (mysql_query("alter table information add(Message varchar(50),Status varchar(10),Crecord varchar(30),
Reson varchar(30)",$con))
{
echo "Table created";
}

$p="insert into information(Message,Status,Crecord,Reson)values
('$a7','$a8','$a9','$a10')";
mysql_query($p);

if(!$dbconnect = mysql_connect('localhost', 'root', 'password')) {
echo "Connection failed to the host 'localhost'.";
exit;
} // if
if (!mysql_select_db('adoption')) {
echo "Cannot connect to database 'adoption'";
exit;
} // if
$table_id = 'information';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query, $dbconnect);
// create a new XML document
$doc = domxml_new_doc('1.0');
// create root node
$root = $doc->create_element('root');
$root = $doc->append_child($root);
$root = $doc->create_element('root');
$root = $doc->append_child($root);
// process one row at a time
while($row = mysql_fetch_assoc($dbresult)) {
// add node for each row
$occ = $doc->create_element($table_id);
$occ = $root->append_child($occ);
// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->create_element($fieldname);
$child = $occ->append_child($child);
$value = $doc->create_text_node($fieldvalue);
$value = $child->append_child($value);
} // foreach
} // while
// get completed xml document
$xml_string = $doc->dump_mem(true);
//echo $xml_string;

$fh = fopen("c:/testdir/file1.xml","w");
fwrite($fh,$xml_string);
fclose($fh);
//$handle = fopen($filename, "w");
//fwrite($handle, $csv_code);
//fclose($handle);
//where $filename ='\\parag.xml';
?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><font face="Algerian" size="5" color="#800000">Thanks For Your Valuable Time
We Will Get Back To You Within Next 48 Hrs &amp; Will Fix the Appointment...</font></p>
</body>
</html>
.................................................. ....................................end........... .................................................. .
Reply With Quote
  #13 (permalink)  
Old 05-16-09, 04:18 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
dgreenhouse i appreciate all the help from you and i am really thank full also.

The purpose of generating the new xml file is the fom data stored in XML will be utilized in a desktop based application later on to produce pdf. that is entire idea of creating new xml. we can generate pdf on web itself but that's not the requirement. The above code is what i have developed. It is generating a XML file but i need a xml file to be generated everytime form is submitted..
Reply With Quote
  #14 (permalink)  
Old 05-16-09, 04:57 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I am really really tensed and need to figure out things.
A feature of the application would be that if user filled half form then, next time it should continue from there itself so i suppose i have to first store all data in database and in the end on or after submission i have to generate new xml file (in some directory on server), for every new submission.

Looking forward for guidance of an expert like you.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write Mysql data to xml via php ragrim Script Requests 0 03-04-09 09:51 PM
For Hire (3 years exp.): Looking for Php, Mysql, AJAX, JavaScript, HTML, XML Barkat Job Offers & Assistance 1 09-25-07 04:15 PM
xml to mysql using php - urgent mianriz PHP 1 12-21-06 03:51 PM
Write in a XML file with php pallabmondal123 PHP 2 04-15-06 05:34 AM
Need help inserting XML file into MySQL database expert01 PHP 3 11-07-05 11:25 PM


All times are GMT -5. The time now is 08:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.