0
I have the following code,where I get event data from a form and php sends it to the xml file, but instead of the.xml events adding new data when the form is replenished,.
<?php
#Obtendo dados dos eventos
$campoTitulo = $_POST['titulo'];
$campoLocal = $_POST['local'];
$campoData = $_POST['data'];
$campoHorario = $_POST['horario'];
$campoDescricao = $_POST['descricao'];
#versao do encoding xml
$dom = new DOMDocument("1.0", "UTF-8");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$root = $dom->createElement("agenda");
$evento = $dom->createElement("evento");
#tags para evento
$nomeEvento = $dom->createElement("titulo", $campoTitulo);
$localEvento = $dom->createElement("local", $campoLocal);
$dataEvento = $dom->createElement("data", $campoData);
$horarioEvento = $dom->createElement("horario", $campoHorario);
$descricaoEvento = $dom->createElement("descricao", $campoDescricao);
#evento adiciona as tags criadas
$evento->appendChild($nomeEvento);
$evento->appendChild($localEvento);
$evento->appendChild($dataEvento);
$evento->appendChild($horarioEvento);
$evento->appendChild($descricaoEvento);
#root adiciona o nó evento
$root->appendChild($evento);
$dom->appendChild($root);
#salvando as informações no arquivo xml
$dom->save("eventos.xml");
header("Content-Type:text/xml");
print $dom->saveXML();
?>
XML file
<?xml version="1.0" encoding="UTF-8"?>
<agenda>
<evento>
<titulo>titulo</titulo>
<local>local</local>
<data>data</data>
<horario>10:00</horario>
<descricao>descricao do evento</descricao>
</evento>
</agenda>
I can’t increment more events, because xml just replaces the values in the tags
Possible duplicate of Skip line in XML with PHP
– NoobSaibot