Hei there! I am making a CMS site and I am at the point where I want my members to be able to edit existing articles.
I have come up with the existing code you see below, the only problem is that it doesnt seem to work. Actually.. I dosnt do any thing. I dosnt even output any error messages. Any help would be appriciated
$id = $_POST['id'];
$text = $_POST['text'];
$title = $_POST['title'];
$categori = $_POST['categori'];
$description = $_POST['description'];
$user= $_COOKIE["SESSION"];
$dom = new DomDocument;
$dom->load('articles.xml');
$root = $dom->documentElement;
$articleelement = $dom->createElement('article');
$articleelement->appendChild(new DOMElement('title',utf8_encode('$title')));
$articleelement->appendChild(new DOMElement('text',utf8_encode('$text')));
$articleelement->appendChild(new DOMElement('categori', '$categori'));
$xpath = new DOMXPath($dom);
$oldnode =$xpath->query("//article[@id='$id']")->item(0);
$change_history_element = $dom->createElement('edited');
$articleelement->appendChild($change_history_element);
$change_history_element->appendChild(new DOMElement('name', utf8_encode('$user')));
$change_history_element->appendChild(new DOMElement('time', time()));
$change_history_element->appendChild(new DOMElement('description',
utf8_encode('$description')));
$root->replaceChild($articleelement, $oldnode);
$dom->saveXML();
This is supposed to take a existing article, edit it and post the time of editing, autor who made the change and save the changes he defines in a form.
NOTE: If some of the variable names are mispelled its because I just changed them from Noriwegian to English to make them understandable.
Cheers, Simon
I have come up with the existing code you see below, the only problem is that it doesnt seem to work. Actually.. I dosnt do any thing. I dosnt even output any error messages. Any help would be appriciated
$id = $_POST['id'];
$text = $_POST['text'];
$title = $_POST['title'];
$categori = $_POST['categori'];
$description = $_POST['description'];
$user= $_COOKIE["SESSION"];
$dom = new DomDocument;
$dom->load('articles.xml');
$root = $dom->documentElement;
$articleelement = $dom->createElement('article');
$articleelement->appendChild(new DOMElement('title',utf8_encode('$title')));
$articleelement->appendChild(new DOMElement('text',utf8_encode('$text')));
$articleelement->appendChild(new DOMElement('categori', '$categori'));
$xpath = new DOMXPath($dom);
$oldnode =$xpath->query("//article[@id='$id']")->item(0);
$change_history_element = $dom->createElement('edited');
$articleelement->appendChild($change_history_element);
$change_history_element->appendChild(new DOMElement('name', utf8_encode('$user')));
$change_history_element->appendChild(new DOMElement('time', time()));
$change_history_element->appendChild(new DOMElement('description',
utf8_encode('$description')));
$root->replaceChild($articleelement, $oldnode);
$dom->saveXML();
This is supposed to take a existing article, edit it and post the time of editing, autor who made the change and save the changes he defines in a form.
NOTE: If some of the variable names are mispelled its because I just changed them from Noriwegian to English to make them understandable.
Cheers, Simon