รบกวนช่วยด้วยค่ะ Error XML โดย PHP ค่ะ มันขึ้น error <b>Catchable fatal error</b>: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null
ต้องการเขียน add XML โดย PHP ค่ะ แล้วมันขึ้น error แบบนี้อ่าค่ะ
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Only one top level element is allowed in an XML document. Error processing resource 'http://localhost/newtemp2/user/adduser...
<b>Catchable fatal error</b>: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null ...
code ที่เขียนมีดังนี้ค่ะ
Code (PHP)
<?php
function writeXML($xml)
{
$fp = fopen('user.xml', 'w+');
fwrite($fp,$xml);
fclose($fp);
}
if(isset($submit))
{
$name = $_POST['name'];
$LastName = $_POST['lastname'];
$position = $_POST['position'];
$EN = $_POST['EN'];
$dep =$_POST['dep'];
$site=$_POST['site'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$time_regis = date("D d F Y h:i:s");
$xmls = new DOMDocument('1.0','utf-8');
if(@$load = $xmls->load("../user/user.xml"))
{
$i=0;
$dom = new DOMDocument('1.0','utf-8');
$nodeList = $xmls->getElementsbytagName('root')->item($i);
$i++;
$oldnode = $dom->importNode($nodeList, true);
$dom->appendChild($oldnode);
$xml_user = $dom->createElement( "User" );
$xml_name = $dom->createElement( "Name",$name );
$xml_lastname = $dom->createElement( "LastName",$lastname );
$xml_position = $dom->createElement("Position",$position);
$xml_en = $dom->createElement("Dep" ,$dep);
$xml_site = $dom->createElement("site",$site);
$xml_tel = $dom->createElement("tel",$tel);
$xml_email = $dom->createElement("email",$email);
$xml_username =$dom->createElement("password",$password);
$xml_timeregis = $dom->createElement( "TimeUpFile", $timeregis );
// Set the attributes.
$xml_user->setAttribute( "ID", $i );
//$count = xml.count("user",[user]);
// Append the whole bunch.
$xml_user->appendChild( $xml_name );
$xml_user->appendChild( $xml_lastname );
$xml_user->appendChild( $xml_position);
$xml_user->appendChild( $xml_en );
$xml_user->appendChild( $xml_site );
$xml_user->appendChild( $xml_tel);
$xml_user->appendChild($xml_email );
$xml_user->appendChild($xml_username );
$xml_user->appendchild($xml_password );
$dom->documentElement->appendChild($xml_user);
// Parse the XML.
$text = $dom->saveXML();
print $text;
writeXML($text);
}
else
{
// Set the content type to be XML, so that the browser will recognise it as XML.
header( "content-type: application/xml; charset=utf-8" );
// "Create" the document.
$xml = new DOMDocument( "1.0", "utf-8" );
//Create root elemets
$xml_root = $xml->createElement( "root" );
// Create some elements.
$xml_user = $xml->createElement( "User" );
// Create another element, just to show you can add any (realistic to computer) number of sublevels.
$xml_name = $xml->createElement( "Name",$name );
$xml_lastname = $xml->createElement( "LastName",$lastname );
$xml_position = $xml->createElement("Position",$position);
$xml_en = $xml->createElement("Dep" ,$dep);
$xml_site = $xml->createElement("site",$site);
$xml_tel = $xml->createElement("tel",$tel);
$xml_email = $xml->createElement("email",$email);
$xml_username =$xml->createElement("password",$password);
$xml_timeregis = $xml->createElement( "TimeUpFile", $timeregis );
// Set the attributes.
$xml_user->setAttribute( "ID", $i );
// Append the whole bunch.
$xml_user->appendChild($xml_name);
$xml_user->appendChild($xml_lastname);
$xml_user->appendChild($xml_position);
$xml_user->appendChild($xml_en);
$xml_user->appendChild($xml_site);
$xml_user->appendChild($xml_tel);
$xml_user->appendChild($xml_email);
$xml_user->appendChild($xml_username);
$xml_user->appendchild($xml_password);
$xml_root->appendChild($xml_user);
// Append the DOMXML.
$xml->appendChild($xml_root);
$text = $xml->saveXML();
print $text;
writeXML($text);
}
}
else
{
?>
<b>Add</b><p/>
<form method="post" name="formxml" action="<?=$SERVER_['PHP_SELF'] ?>">
<table width="769" border="0" cellspacing="0">
<tr><td height="33" colspan="4"><center>
Set Track Element
</center></td></tr>
<tr>
<td width="124">Name : </td><td width="291"><input type="text" name="name"></td>
<td width="88">LastName :</td>
<td width="258"><label>
<input type="text" name="lastname" id="lastname">
</label></td>
</tr>
<tr>
<td>Position : </td><td><input type="text" name="position" /></td>
<td>EN : </td>
<td><label>
<input type="text" name="en" id="en">
</label></td>
</tr>
<tr>
<td>Department :</td><td><input type="text" name="dep" /></td>
<td>Site :</td>
<td><label>
<input type="text" name="site" id="site">
</label></td>
</tr>
<tr><td colspan="4"></td></tr>
<tr>
<td>Tel :</td>
<td><label>
<input type="text" name="tel" id="tel">
</label></td>
<td>Email :</td>
<td><label>
<input type="text" name="email" id="email">
</label></td>
</tr>
<tr>
<td>User Name :</td>
<td><label>
<input type="text" name="textfield" id="textfield">
</label></td>
<td>Password :</td>
<td><label>
<input type="text" name="textfield2" id="textfield2">
</label></td>
</tr>
<tr><td colspan="4"><center><input type="submit" name="submit" value=" Add ">
<label>
<input type="reset" name="Reset" id="button" value="Reset">
</label>
</center></td></tr>
</table>
</form>
<?
}
?>
คือไม่ทราบว่าเป็นเพราะอะไรค่ะ นั่งไล่หลายรอบแล้ว ก็ยังไม่ได้ รบกวนด้วยค่ะTag : PHP
Date :
2010-08-11 09:50:50
By :
bbeniac
View :
1151
Reply :
0
Load balance : Server 00