Jump to content

Use Form Data to Create XML File?


Sepia

Recommended Posts

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.

 

Something like this:

http://www.edutech.ch/vista/imsimport.php

Go down to User Section Enrollment

 

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

 

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);

 

Does anyone know of another tutorial is have any pointers to get me started?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/59517-use-form-data-to-create-xml-file/
Share on other sites

<?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\" ?>";
        $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);
?>

 

Should work.

Thanks but now I am getting:

parse error: syntax error, unexpected $end in xml/php/employee.php on line 31

 

<?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\" ?>";
        $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);
?>

 

<?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\" ?>";
        $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);
}
?>

  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.