Heres the thing.
I did this tutorial about making making a small site where you can add articles and edit them using domxml, well i found that domxml doesnt work with php5 so i had to try and use dom. Im mostly guessing when im trying to find what i need on php.net manual. Anyways it seams like im gonna be able to do... maybe, hehe (trying anyways) But i come to a full stop now. Ill show the code for it below. Everything works fine, but the article id. in the form im using to fill out the information: When i fill in a article id, a name. It doesnt seam to save this. Instead it gets only a long number. I dont get it, it is suposed to show the name i give it and this number is just there to make sure the article name is uniqe. (?)
$root->setAttribute($id, "id"); /*This is where i try to set a name to the article, but i only get a number... This is the part where i dont understand whats wrong*/
... Ill just show you the full code
<?php
//stripslashes
$headline = stripslashes($headline);
$name = stripslashes($name);
$email = stripslashes($email);
$abstract = stripslashes($abstract);
$keywords = stripslashes($keywords);
//create document root
$doc = new DOMDocument('1.0', 'iso-8859-1'); //Heres where i started making changes to the code from domxml to dom
$root = $doc->createElement("article");
$root = $doc->appendChild($root);
//add ID attribute
//FIRST, let's make sure that the id they chose isn't going to overwrite a file!
$dh = opendir('./xml/');
while ($file = readdir($dh)){
$string = $id . ".xml";
if (eregi("^\\.\\.?$", $file)) {
continue;
}
if (eregi($string, $file)){
$time = date("U"); //number of seconds since unix epoch
$id = $id . "-" . $time;
}
}
$root->setAttribute($id, "id"); /*This is where i try to set a name to the article, but i only get a number... This is the part where i dont understand whats wrong*/
//create headline
$head = $doc->createElement("headline");
$head = $root->appendChild($head);
$htext = $doc->createTextNode($headline);
$htext = $head->appendChild($htext);
//create author name
$aname = $doc->createElement("author");
$aname = $root->appendChild($aname);
$atext = $doc->createTextNode($name);
$atext = $aname->appendChild($atext);
//create author email
$mail = $doc->createElement("email");
$mail = $root->appendChild($mail);
$mtext = $doc->createTextNode($email);
$mtext = $mail->appendChild($mtext);
//create abstract
$abs = $doc->createElement("abstract");
$abs = $root->appendChild($abs);
$abstext = $doc->createTextNode($abstract);
$abstext = $abs->appendChild($abstext);
//create keyword listing
$keylisting = $doc->createElement("keywords");
$keylisting = $root->appendChild($keylisting);
$ktext = $doc->createTextNode($keywords);
$ktext = $keylisting->appendChild($ktext);
//create status, always in progress when first created
$stat = $doc->createElement("status");
$stat = $root->appendChild($stat);
$stat_text = $doc->createTextNode($status);
$stat_text = $stat->appendChild($stat_text);
//create paras
if (is_array($body)){
foreach ($body as $K => $V){
if ($V != ""){
$V = stripslashes($V);
$para = $doc->createElement("para-$K");
$para = $root->appendChild($para);
$ptext = $doc->createTextNode($V);
$ptext = $para->appendChild($ptext);
//$para->set_attribute('order', $K);
}
}
}
//write to the file
$filename = "./xml/".$id . ".xml";
$doc->save($filename);
//send user back to adminindex
header("Location:adminindex.php");
?>
I hope someone understands my Jibberish, and hope someone can help me understand what im doing wrong. Thanx a million for any help.