Ok, so here is what I want to do (NOTE: I am not familiar with PHP yet):
I have a registration form for films / TV shows, etc. Then the data from the completed form is registered (register.php) and sent to the MySQL database, which works fine. Here comes, but: I also want, in the same register file (register.php), the data to be stored in an existing XML file (data.xml). It is important to note that each successfully submitted form is stored in the same XML file (data.xml).
I show all the registered βmoviesβ in the HTML table through a while loop, which now collects data from my database. I also ask for help, somewhere outside the table, to add a button that generates / displays the contents of the XML file in a new tab (?). Do not right-click to view the source, since the table data is collected from MySQL, this is not possible.
Here is what I have so far (this allows me to save each view in the data.xml file, but is replaced if another view is done - I want to add NOT replace):
First of all, index.php:
<form enctype="multipart/form-data" action="core/register.php" method="post" autocomplete="true"> <p><input type="text" name="name" placeholder="Program name" /></p> <p><input type="date" name="date" placeholder="Program date" /></p> <p><input type="time" name="time" placeholder="Program time" /></p> <p><input type="text" name="bline" placeholder="B-line" /></textarea></p> <p><textarea name="synopsis" placeholder="Program synopsis" /></textarea></p> <p><textarea name="leadtext" placeholder="Lead text" /></textarea></p> <p><input type="url" name="url" placeholder="URL" /></p> <p><input type="submit" value="Register" name="register" /></p> </form>
Next, data.xml:
<?xml version="1.0" encoding="UTF-8"?> <programs> <program> <name></name> <date></date> <start_time></start_time> <b-line></b-line> <synopsis></synopsis> <leadtext></leadtext> <url></url> </program> </programs>
Finally, register.php:
require_once('db.php'); $str = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="xsl.xsl"?><programs></programs>'; $xml = simplexml_load_string($str); $name = $_POST['name']; $date = $_POST['date']; $time = $_POST['time']; $bline = $_POST['bline']; $synopsis = $_POST['synopsis']; $leadtext = $_POST['leadtext']; $url = $_POST['url']; $name = htmlentities($name, ENT_COMPAT, 'UTF-8', false); $date = htmlentities($date, ENT_COMPAT, 'UTF-8', false); $time = htmlentities($time, ENT_COMPAT, 'UTF-8', false); $bline = htmlentities($bline, ENT_COMPAT, 'UTF-8', false); $synopsis = htmlentities($synopsis, ENT_COMPAT, 'UTF-8', false); $leadtext = htmlentities($leadtext, ENT_COMPAT, 'UTF-8', false); $url = htmlentities($url, ENT_COMPAT, 'UTF-8', false); $xml->program->addChild('name', $name); $xml->program->addChild('date', $date); $xml->program->addChild('start_time', $time); $xml->program->addChild('b-line', $bline); $xml->program->addChild('synopsis', $synopsis); $xml->program->addChild('leadtext', $leadtext); $xml->program->addChild('url', $url); $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $doc->preserveWhiteSpace = true; $doc->loadXML($xml->asXML(), LIBXML_NOBLANKS); $doc->save('data.xml');
I searched for a watch, not finding exactly what I was looking for. I also tried my best to try many of my own "non-working solutions." In addition, I have selected parts of my code that are relevant to the answers on this.