// ensure complete form was submitted if (!isset($_POST["name"]) || !isset($_POST["item"])) { header("Location: http://www.cs75.net/lectures/4/src/lunch/lunch.php"); exit; } // open XML file for reading + writing $handle = fopen("orders.xml", "r+"); // acquire exclusive lock flock($handle, LOCK_EX); // read contents of XML file $contents = fread($handle, filesize("orders.xml")); // build DOM out of contents $xml = new SimpleXMLElement($contents); // add order $order = $xml->addChild("order"); $order->addChild("name", $_POST["name"]); $order->addChild("item", $_POST["item"]); // overwrite original XML file rewind($handle); fwrite($handle, $xml->asXML()); fclose($handle); ?>