Use Form Data to Create XML File?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sepai
Forum Newbie
Posts: 3
Joined: Wed Jul 11, 2007 3:54 pm

Use Form Data to Create XML File?

Post by Sepai »

I am brand new to PHP but would like to create a form in an HTML page that will use the data entered into it to display an XML file.

I fould this tutorial:
http://www.topxml.com/php_simplexml/default.asp

but didnt really understand it and was getting error messages when trying to use it:
Parse error: syntax error, unexpected T_STRING in /xml/php/employee.php on line 8

Code: Select all

$xml_dec = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
Does anyone know of another tutorial is have any pointers to get me started?

Thanks.
Last edited by Sepai on Wed Jul 11, 2007 4:33 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you posted the lines before that line too?
Sepai
Forum Newbie
Posts: 3
Joined: Wed Jul 11, 2007 3:54 pm

Post by Sepai »

Yep sure:

Code: Select all

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\" ?>";
        $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";
	$fp = fopen($default_dir,'w');
        $write = fwrite($fp,$xml_doc);
Thats the whole php file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Outside of a missing closing brace for the if, I don't see any syntax errors.
Sepai
Forum Newbie
Posts: 3
Joined: Wed Jul 11, 2007 3:54 pm

Post by Sepai »

Could it be something else?

This is what I want to create:
http://www.edutech.ch/vista/imsimport.php
Go down to User Section Enrollment

Someting similiar to that.
Post Reply