Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,175 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,186 people online right now. Registration is fast and FREE... Join Now!




create xml from php

 
Reply to this topicStart new topic

create xml from php, I'm trying to create a form that will generate an xml file

bkeller99
29 Aug, 2008 - 09:46 AM
Post #1

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 4

Hello, man I just found this site and seems to good to be true. Well here goes.
I am trying to create a form that generates an xml file.

here is the form code:
CODE
<html>

<head>

<title>XML Employee Data</title>

</head>

<body>

<p>Employee Data</p>

<form method="POST" action="php/convert_to_xml.php">

<input type="hidden" name="create_employee" value="true">

<table>

  <tr>

    <td width="27%">Employee Name:</td>

    <td width="73%"><input type="text" name="empName" size="20"></td>

  </tr>

  <tr>

    <td width="27%">Employee Address</td>

    <td width="73%"><input type="text" name="empAddress" size="73"></td>

  </tr>

  <tr>

    <td width="27%">Employee SSN</td>

    <td width="73%"><input type="text" name="empSSN" size="20"></td>

  </tr>

  <tr>

    <td width="27%">Company Name</td>

    <td width="73%"><input type="text" name="empCompany" size="73"></td>

  </tr>

  <tr>

    <td width="27%">XML File Name</td>

    <td width="73%"><input type="text" name="xmlfileName" size="20"></td>

  </tr>

</table>

  <p align="center">

  <input type="submit" value="Submit" name="B1"></p>

</form>

</body>

</html>


here is the php file ( convert_to_xml.php )
CODE
<?php
if(isset($_POST['create_employee'])){

        echo "Employee Data Posted";

        $xmlfileName = $_POST['xmlfileName'];

        $empName = $_POST['empName'];

        $empAddress = $_POST['empAddress'];

        $empSSN = $_POST['empSSN'];

        $empCompany = $_POST['empCompany'];

        $xml_dec = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

/* After gathering all data from the form then, I created a variable to hold all the data entered by
user in string format.  */


        $rootELementStart = "<employee>";

        $rootElementEnd = "</employee>";

        $xml_doc=  $xml_dec;

        $xml_doc .=  $rootELementStart;

        $xml_doc .=  "<employeename>";

        $xml_doc .=  $empName;

        $xml_doc .=  "</employeename>";

        $xml_doc .=  "<employeeaddress>";

        $xml_doc .=  $empAddress;

        $xml_doc .=  "</employeeaddress>";

        $xml_doc .=  "<SSN>";

        $xml_doc .=  $empSSN;

        $xml_doc .=  "</SSN>";

        $xml_doc .=  "<company>";

        $xml_doc .=  $empCompany;

        $xml_doc .=  "</company>";

        $xml_doc .=  $rootElementEnd;

        $default_dir = "xml_files/";

        $default_dir .=   $xmlfileName .".xml";

/*Here I have taken default directory as xml_files directory.

After creating string representation of employee data, I have used following PHP script to store in the file */

$fp = fopen($default_dir,'w');

            $write = fwrite($fp,$xml_doc);
?>


when I submit the form I receive this error:

Parse error: parse error, unexpected $end in C:\Program Files\xampp\htdocs\testsite\php\convert_to_xml.php on line 68

According to phpinfo() I have dom/xml version 20031129
libxml Version 2.6.22

I'm eventually going to modify this form and php to do mortgage calculations, and the xml file will be used to generate a flash based line and bar graph.

Can you spot anything?!


User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Create Xml From Php
29 Aug, 2008 - 09:57 AM
Post #2

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 862



Thanked: 89 times
Dream Kudos: 50
My Contributions
You have an unclosed brace, looks like you didn't close the if (isset... {
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Create Xml From Php
29 Aug, 2008 - 10:11 AM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
yes, you need a } at the end before ?>
User is offlineProfile CardPM
+Quote Post

bkeller99
RE: Create Xml From Php
29 Aug, 2008 - 10:52 AM
Post #4

New D.I.C Head
*

Joined: 29 Aug, 2008
Posts: 4

QUOTE(JBrace1990 @ 29 Aug, 2008 - 11:11 AM) *

yes, you need a } at the end before ?>

Whoa..I must have looked at that code for 3 days straight and didn't see it!
Thanks to both of you...
Works like a champ now.
Now I'm off to see if I can generate mortgage calculations and convert totals to a graph. THanks a ton!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:36AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month