2014-10-10 169 views
0

好吧,我可以这样做%100错误我遇到了麻烦PHP的XML我只是想保存客户的详细信息.......(不是要安全但只是学习如何做到这一点)
通过PHP保存到XML

的HTML是一种简单的形式
的名字,姓氏,密码,电子邮件,以及可选的电话号码(不需要此刻)

PHP代码开始javascript之后用Javascript调用它..

PHP

<?php 
      // header('Content-Type: text/xml'); 
       session_register('Customer'); 
       //session_start('customer'); 
      $doc = new DOMDocument(); 
      $doc->load('customer.xml'); 

      $firstname = $_GET["firstName"]; 
      $lastname = $_GET["lastName"]; 
      $email = $_GET["email"]; 
      $password = $_GET["password"]; 

      $MDA = $_SESSION["Customer"]; //assign the session varaible to MDA 


      if (isset($firstname)) { 
      $customerArray = array(); 
      $customerArray['firstname'] = $firstname; 
      $customerArray['lastname'] = $lastname; 
      $customerArray['email'] = $email; 
      $customerArray['password'] = $password; 
      $MDA[$firstname] = $customerArray; 
      $_SESSION["Customer"] = $MDA; 
       ECHO (toXml($MDA)); 
      } 


      function toXml($MDA) 
      {      
       $doc = new DomDocument('1.0'); 
       $Customer = $doc->createElement('Customers'); 
       $Customer = $doc->appendChild($Customer); 
       $root = $doc->appendChild($doc->createElement('Root')); 

       foreach ($MDA as $a => $b) 
       { 
        $nodeA = $doc->createElement('NodeA'); 
        $root->appendChild($nodeA); 
        $nodeA->appendChild($attr1); 
        $attr1 = $doc->createAttribute('firstname'); 
        $attr1->appendChild($doc->createTextNode($a['firstname'])); 

       $attr = $doc->createElement('firstname'); 
       $attr = $Customer->appendChild($person); 

       $lastname = $doc->createElement('lastname'); 
       $lastname = $person->appendChild($lastname); 
       $value = $doc->createTextNode($a); 
       $value = $lastname->appendChild($value); 

       $email = $doc->createElement('email'); 
       $email = $person->appendChild($email); 
       $value2 = $doc->createTextNode($b['email']); 
       $value2 = $email->appendChild($value2); 

       $password = $doc->createElement('password'); 
       $password = $person->appendChild($password); 
       $value3 = $doc->createTextNode($b['password']); 
       $value3 = $password->appendChild($value3);   
       } 

       $doc->formatOutput = true; 
       $strXml = $doc->saveXML(); 
       //$doc->save('customer.xml'); 
       return $strXml; 
      } 
     ?> 

和不知道它需要的,但的JavaScript ...它只是检查密码ATM

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


     function test() 
     { 
      var firstname = document.getElementById("firstName").value; 
      var lastname = document.getElementById("lastName").value; 
      var email = document.getElementById("email").value; 
      var password = document.getElementById("password").value; 
      var password2 = document.getElementById("password2").value; 
      var number = document.getElementById("pNumber").value; 
      var type = ""; 
      var input = document.getElementsByTagName("input"); 
       xHRObject.open("GET", "testregristation.php?", true); 
       xHRObject.onreadystatechange = function() { 
        if (xHRObject.readyState == 4 && xHRObject.status == 200) 
        if (password != password2) { 
        alert("Password is wrong"); 

        } 
        else 
        { 
         alert("test " +firstname + " " + lastname + " " + email + " : " + password); 
         document.getElementById('information').innerHTML = xHRObject.responseText; 
       } 
       xHRObject.send(); 
     }; 
     } 
+0

所以..什么是错误? – Matheno 2014-10-10 14:59:43

+0

它没有将特定信息保存到我的XML:|我不知道为什么或为什么 – 2014-10-10 15:00:55

+0

变量是否填满? customerArray是否创建?尝试循环遍历代码一步一步,看看它打破了什么地方 – Matheno 2014-10-10 15:03:47

回答

0

已过期浏览器的问题,这在Firefox

正常工作