G'day,HTML에서 XML로 텍스트 추가
내 과제의 일환으로, 사용자가 입력 한 세부 정보를 등록 양식에 XML 문서로 저장해야합니다.
나는 그럭저럭 할 수 있었다. 그러나 문제는 새로운 사용자가 등록 할 때, 오래된 세부 사항이 새로운 사용자의 세부 사항으로 덮어 쓰기된다는 것이다. 결국 XML 문서에는 오직 하나의 사용자 세부 사항 만 있습니다.
이전 세부 정보를 "보존"하면서 새 사용자의 세부 정보를 저장하는 방법이 있는지 궁금합니다.
어떤 도움에 감사드립니다 :)
HTML 코드 -
<form id="rego" name="rego" method="get" action="register2.php">
<table width="719" border="0">
<tr>
<td><div align="right">Email Address</div></td>
<td><label for="email"></label>
<input type="text" name="email" id="email" maxlength="50" /></td>
</tr>
<td width="376"><div align="right">First Name</div></td>
<td width="333"><label for="firstName"></label>
<input type="text" name="firstName" id="firstName" maxlength="15" /></td>
<td><div id="underInput"></div></td>
</tr>
<tr>
<td><div align="right">Last Name</div></td>
<td><label for="lastName"></label>
<input type="text" name="lastName" id="lastName" maxlength="20" /></td>
</tr>
<tr>
<td><div align="right">Phone Number</div></td>
<td><label for="phoneNumber"></label>
<input type="text" name="phoneNumber" id="phoneNumber" maxlength="10" /></td>
</tr>
<tr>
<tr>
<td><div align="right">Password</div></td>
<td><label for="password"></label>
<input type="password" name="password" id="password" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">Re-type password</div></td>
<td><label for="confirmPassword"></label>
<input type="password" name="confirmPassword" id="confirmPassword" maxlength="30" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="Submit" name="Submit" id="Submit" value="Submit"/><!--onclick="saveForm();"--></td>
</tr>
PHP 코드 (내가 DOM을 사용하고 있습니다) - 내가 어떤 사과
<?php
$CustomerEmail = $_GET["email"];
$CustomerFName = $_GET["firstName"];
$CustomerLName = $_GET["lastName"];
$CustomerPhoneNumber = $_GET["phoneNumber"];
$CustomerPassword = $_GET["password"];
$CustomerConfirmPassword = $_GET["confirmPassword"];
$doc = new DomDocument('1.0');
$root = $doc->createElement('customers');
$root = $doc->appendChild($root);
$customer = $doc->createElement('customer');
$customer = $root->appendChild($customer);
$email = $doc->createElement('email');
$email = $customer->appendChild($email);
$valueEmail = $doc->createTextNode($CustomerEmail);
$valueEmail = $email->appendChild($valueEmail);
$fName = $doc->createElement('firstname');
$fName = $customer->appendChild($fName);
$valueFName = $doc->createTextNode($CustomerFName);
$valueFName = $fName->appendChild($valueFName);
$lName = $doc->createElement('lastname');
$lName = $customer->appendChild($lName);
$valueLName = $doc->createTextNode($CustomerLName);
$valueLName = $lName->appendChild($valueLName);
$phone = $doc->createElement('phone');
$phone = $customer->appendChild($phone);
$valuePhone = $doc->createTextNode($CustomerPhoneNumber);
$valuePhone = $phone->appendChild($valuePhone);
$password = $doc->createElement('password');
$password = $customer->appendChild($password);
$valuePassword = $doc->createTextNode($CustomerPassword);
$valuePassword = $password->appendChild($valuePassword);
$confirmPassword = $doc->createElement('confirmpassword');
$confirmPassword = $customer->appendChild($confirmPassword);
$valueConfirmPassword = $doc->createTextNode($CustomerConfirmPassword);
$valueConfirmPassword = $confirmPassword->appendChild($valueConfirmPassword);
$doc->save('customer2.xml');
?>
불편 함.
언제든지 XML에 데이터를 추가 할 수 있습니다. 하지만 XML을 조작하는 기술에 대해 자세히 설명해 주시겠습니까? 일부 코드를 게시하면 greate 지원도 가능합니다. – melc
GET 메서드를 사용하여 HTML에서 textboxes의 값을 가져 와서 각 태그에 값을 자식으로 추가하는 PHP 파일에 전달합니다. 그것은 모두 간단한 것입니다. 죄송합니다. 여기서는 코드가 필요 없다고 생각했습니다. 여전히 원하는 경우 일부 코드를 게시 할 수 있습니다. 감사합니다. – callMeJava
자세한 내용은 필요합니다. 문제를 파악할 수 있도록 코드를 확인해야합니다. – jrock2004