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


Mysql to write xml

Reply
  #1 (permalink)  
Old 05-09-09, 02:43 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Hazard Mysql to write xml

i have multi page forms , which i have connected to mysql, now what i want is to write data of forms in xml whenever submitted but i want it to write a new xml file everytime.

Is it possible? If yes then how? please provide a script if any one can, it will be highly appreciated.

Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-09-09, 03:46 AM
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
Unfortunately, you'll have to write it yourself, but look into PHP's xml functions.

You could just emit xml data using PHP's print or echo commands.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-09-09, 03:45 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
I googled "php form to xml" and found a bunch of examples but nothing exactly what you need.
It should be pretty easy to make a quick and dirty script to something like this.

First note that this is particular dangerous because your going $_POST -> File and if the file is in a public place it can be a problem. Be sure to store them outside an execution folder.

PHP Code:

<?php
$doc 
new_xmldoc('1.0');
$root $doc->add_root('data');
$data $root->new_child('data','');
foreach(
$_POST as $k=>$v){
$data->new_child($k,$v);
}
file_put_contents($_POST['filename'],$doc->dumpmem());
?>
So this dumps the $_POST info in to a file that you passed to it via $_POST['filename'] using xmldoc. Untested.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads

Last edited by infinitylimit; 05-09-09 at 03:48 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-10-09, 05:47 PM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I do understand that we can write data into xml. But i want tocreate a new xml file everytime data is submitted , is it possible?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-10-09, 07:45 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
Of course it's possible.

Just create a new file with a slightly different name each time - if that's what you need.

You could use tempnam(), tmpfile() or some other file naming scheme of your own design.

The directory you create the file in must be writable by the user that the webserver is running as.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-10-09, 08:34 PM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
That's wonderful. but it would be gr8 if you could write down a small example. It would be a great help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-11-09, 01:21 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Or if it is possible to store data of multi-page form in sessions and database also, which in the end will create xml and pass the same data into database as well?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-11-09, 01:35 AM
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
What do you have already?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 05-11-09, 03:32 AM
t-soft t-soft is offline
Newbie Coder
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
i have multi page form whichstores data in mysql database. Now i am not able to save data from MySql to XML.
Though everytime form is submitted i would require a new XML file to be created.

Thanx in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 05-12-09, 05:22 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
Also, you kept saying "database" so I assume you want to store the values in the database.

In the database table, I'd use a "blob" field to store the data.

For multi-page forms, I'd either track the variables in session variables or if cookies aren't set, you'll need to either use URL cookies (really ugly)
or save the inter-page variables in a temporary variables' table.

If a temporary table, I'd opt for serializing the values keyed on the form id and ip address of the visitor.
(see: php's serialize() and unserialize() functions)

The temporary variables table uses a blob field also for the serialized values and the structure would be something like:
form_id (varchar(16)), ip_addr (char(15) for ipv4), variables (blob).

You've provided very little on the program structure, so I really can't help beyond the former and the following.
(I can't do your work for you.)

What is the logic of saving a new XML page?

Do you know how to create an XML page by just using code?

Why don't you just create a custom XML wrapper?

Maybe something like:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<form id="form_id">
  <variables>
    <variable name="variable1">variable1 value</variable>
    <variable name="variable2">variable2 value</variable>
  </variables>
</form>
Or something simpler?

Example:
Code:
<?php

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

  $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
  $xml .= '<form id="' . $_POST['form_id'] . '">' ."\n";
  $xml .= '<variables>'."\n";
  $xml .= '<variable name="var1">' . $_POST['var1'] . '</variable>' ."\n";
  $xml .= '<variable name="var2">' . $_POST['var2'] . '</variable>' ."\n";
  $xml .= '<variable name="var3">' . (isset($_POST['var3']) ? 'on' : '') . '</variable>' ."\n"; // note test for checkbox
  $xml .= '</variables>'."\n";
  $xml .= '</form>';

header ("content-type: text/xml");
print $xml;
exit;
}

?>
<html>
<body>
<form action="" method="post">
<input type="hidden" name="form_id" value="form1" />
<input type="text" name="var1" /><br />
<input type="text" name="var2" /><br />
<input type="checkbox" name="var3" /><br />
<input type="submit" name="submit" value="Click Me" /><br />

</form>
</body>
</html>

Last edited by dgreenhouse; 05-12-09 at 05:43 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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 10:51 PM
For Hire (3 years exp.): Looking for Php, Mysql, AJAX, JavaScript, HTML, XML Barkat Job Offers & Assistance 1 09-25-07 05:15 PM
xml to mysql using php - urgent mianriz PHP 1 12-21-06 04:51 PM
Write in a XML file with php pallabmondal123 PHP 2 04-15-06 06:34 AM
Need help inserting XML file into MySQL database expert01 PHP 3 11-08-05 12:25 AM


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