Jump to content

updating XML document


iamali84

Recommended Posts

Does anyone know how to update an XML document from data posted through a HTML form using PHP? I've figured out how to write to an XML document using this code that I found:

 

(HTML)

<html>
<head>
<title>Employee Data</title>
</head>
<body>

<p>Employee Data</p>

<form method="POST" action="employee.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>
</table>

  <p align="center">

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

</body>
</html>

 

(PHP)

<?
if(isset($_POST['create_employee'])){

        echo "Employee Data Posted";
	$xmlfileName = 'filename';
        $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 = "";
        $default_dir .=   $xmlfileName .".xml";

	$fp = fopen($default_dir,'a+');
	$write = fwrite($fp,$xml_doc);
	}
?>

 

But I'm stuck on simply updating the file instead of overwriting it. Any ideas anyone? Thanks :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.