2016-10-17 3 views
1

양식을 생성하려고하는데 XML 문서에 게시하지만 코드에서 "필드를 올바르게 채웠는지 확인하십시오"라는 코드를 계속 사용합니다. 변수를 적절하게 제공했을 때 registration.php 파일에서. html, javascript 및 php의 세 섹션이 있습니다.변수가 PHP에서 if 문에서 읽히지 않습니다

"...firstname=" + firstname + "&lastname" + lastname + "&password=" 

대비로 :

"...firstname=" + firstname + "&lastname=" + lastname + "&password=" 

이 수단 내가 갖는 출력은 당신이 (registerCustomer() 함수 내에서) 여기에 서명 핵심 등호를 놓치고 생각

<html> 
    <head> 
    <title>A Simple Example</title> 
    </head> 
    <body> 
    <script src="clientSideScripts.js"></script> 
    <h1>Registration Page </h1> 
    <table border="0"> 
    <form> 
    <tr> 
     <td><strong>Firstname:</strong></td> 
     <td> 
      <input type="text" name="firstname" id="firstname" required /> 
     </td> 
    </tr> 
    <tr> 
     <td><strong>Lastname:</strong></td> 
     <td> 
      <input type="text" name="lastname" id="lastname" required /> 
     </td> 
    </tr> 
    <tr> 
     <td><strong>Password:</strong></td> 
     <td> 
     <input type="password" id="userPassword" name="password" required/> 
     </td> 
    </tr> 
    <tr> 
     <td><strong>Confirm Password:</strong></td> 
     <td> 
     <input type="password" id="confirmPassword" name="pwdfield" required/> 
     </td> 
    </tr> 
    <tr> 
     <td><strong>Email:</strong></td> 
     <td> 
     <input type="email" name="email" id="email" value="" required pattern="[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$" /> 
     </td> 
    </tr> 
    <tr> 
     <td><strong>Contact Phone:</strong></td> 
     <td> 
     <input type="text" name="phone" id="phone" value=""/> 
     </td> 
    </tr> 
    <td> 
     <input type="button" value="Register" onclick="registerCustomer();"/> 
    </td> 
    </form> 
    <div id="information"/> 
</body> 
</html> 


var xHRObject = false; 

if (window.XMLHttpRequest) 
    xHRObject = new XMLHttpRequest(); 
else if (window.ActiveXObject) 
    xHRObject = new ActiveXObject("Microsoft.XMLHTTP"); 

function validatePassword() 
{ 
     var a = document.getElementById("userPassword"); 
     var b=document.getElementById("confirmPassword"); 
     return a.value == b.value; 
} 

function registerCustomer() 
{ 
    if(!validatePassword()) 
     alert("The passwords don't match."); 
    else 
    { 
     var firstname = document.getElementById("firstname").value; 
     var lastname = document.getElementById("lastname").value; 
     var password = document.getElementById("userPassword").value; 
     var email = document.getElementById("email").value; 
     var phone = document.getElementById("phone").value; 
     var url = "registration.php?firstname=" + firstname + "&lastname" + lastname + "&password=" + password + "&email=" + email + "&phone=" + phone; 
     xHRObject.open("GET", url , true); 
     xHRObject.onreadystatechange = function() 
     { 
      if (xHRObject.readyState == 4 && xHRObject.status == 200) 
       document.getElementById('information').innerHTML = xHRObject.responseText + "<br><a href='buyonline.htm'>back</a>"; 
     } 
     xHRObject.send(null); 
    } 
} 


function customerLogin() 
{ 
     var email = document.getElementById("email").value; 
     var password = document.getElementById("password").value; 
     var url = "login.php?email=" + email + "&password=" + password; 
     xHRObject.open("GET", url , true); 
     xHRObject.onreadystatechange = function() 
     { 
      if (xHRObject.readyState == 4 && xHRObject.status == 200) 
       document.getElementById('information').innerHTML = xHRObject.responseText + "<br><a href='buyonline.htm'>back</a>"; 
     } 
     xHRObject.send(null); 
} 

<?php 
if(isset($_GET["firstname"]) && isset($_GET["lastname"]) && isset($_GET["password"]) && isset($_GET["email"])) 
{ 
    if(isEmailUnique()) 
     insertCustomer(); 
    else 
     echo "This email is already taken, please choose another one."; 
} 
else echo "Please make sure you filled in the fields correctly."; 

function getLastId(){ 
    $id = 0; 
    $xmlFile = "../../data/customer.xml"; 
    try 
    { 
     $dom = DOMDocument::load($xmlFile); 
     $customers = $dom->getElementsByTagName("customer"); 

     foreach($customers as $node) 
     { 
      $cID = $node->getElementsByTagName("id"); 
      $cID = $cID->item(0)->nodeValue; 
      if (($id < $cID)) $id = $cID; 
     } 
    } 
    catch(Exception $e) 
    { 
     $doc = new DomDocument('1.0'); 
     $customers = $doc->createElement('customers'); 
     $customers = $doc->appendChild($customers); 

     $doc->saveXML(); 
     return 1; 
    } 
    return $id; 
} 

function insertCustomer() 
{ 
    try { 
     $xmlFile = "../../data/customer.xml"; 
     $doc = DOMDocument::load($xmlFile); 
     $doc->formatOutput = true; 
     $customer = $doc->createElement("customer"); 

     $Customers = $doc->getElementsByTagName("Customers"); 


     $customer = $Customers->item(0)->appendChild($customer); 
     $newID = getLastId() + 1; 
     $id = $doc->createElement('id'); 
     $idValue = $doc->createTextNode($newID); 
     $id->appendChild($idValue); 
     $customer->appendChild($id); 


     $name1 = $doc->createElement('firstname'); 
     $nameValue = $doc->createTextNode($_GET["firstname"]); 
     $value2 = $name1->appendChild($nameValue); 
     $name = $customer->appendChild($name1); 

     $name = $doc->createElement('lastname'); 
     $nameValue = $doc->createTextNode($_GET["lastname"]); 
     $value2 = $name->appendChild($nameValue); 
     $name = $customer->appendChild($name); 

     $name = $doc->createElement('password'); 
     $nameValue = $doc->createTextNode($_GET["password"]); 
     $value2 = $name->appendChild($nameValue); 
     $name = $customer->appendChild($name); 


     $name = $doc->createElement('email'); 
     $nameValue = $doc->createTextNode($_GET["email"]); 
     $value2 = $name->appendChild($nameValue); 
     $name = $customer->appendChild($name); 

     $name = $doc->createElement('phone'); 
     $nameValue = $doc->createTextNode($_GET["phone"]); 
     $value2 = $name->appendChild($nameValue); 
     $name = $customer->appendChild($name); 

     echo "<xmp>".$doc->save($xmlFile)."</xmp>"; 

    } 
    catch(Exception $e) { echo $e;} 

    echo "customer successfully registered and your new Id = ". $newID; 
} 


function isEmailUnique() 
{ 
    $xmlFile = "../../data/customer.xml"; 
    try 
    { 
     $dom = DOMDocument::load($xmlFile); 
     $customers = $dom->getElementsByTagName("customer"); 

     foreach($customers as $node) 
     { 
      $email = $node->getElementsByTagName("email"); 
      $email = $email->item(0)->nodeValue; 

      if (($email == $_GET["email"])) return false; 
     } 
    } 
    catch(Exception $e) 
    { 
     $doc = new DomDocument('1.0'); 
     $customers = $doc->createElement('customers'); 
     $customers = $doc->appendChild($customers); 

     $doc->saveXML(); 
     return true;  
    } 
    return true; 
} 
?> 
+0

JAVASCRIPT 안에''태그해야하고 정말' ....'뿐만 아니라 태그 – RiggsFolly

+0

당신은 하나의 내부 테스트하기 위해 여러 필드를 배치 할 수 있습니다'isset'가있는 경우 모든 내부해야한다 그리고,'isset ($ _GET [ "firstname"], $ _GET [ "lastname"], $ _GET [ "password"], $ _GET [ "email"])' – RiggsFolly

답변

3

입니다 GET 인덱스 lastname이 설정되지 않습니다.

+0

감사합니다. –

관련 문제