2013-09-24 4 views
0

유니 코드 할당을 위해 작동하는 코드를 얻으려고하고 있습니다. 아직 학습 중이지만 클래스 변수가 작동하지 않는 이유를 이해하려고 조금 미쳤다고 느낍니다. .XMLHttpRequest를 통해 PHP 클래스 변수를 업데이트하지 못했습니다.

class Users { 

    //Variables 
    protected $_userName; 
    protected $_password; 
    protected $_login; 
    protected $_firstName; 
    protected $_lastName; 
    protected $_email; 
    protected $_phone; 
    protected $_addressStreet; 
    protected $_addressCity; 
    protected $_addressState; 
    protected $_company; 

    public function __construct() { 
     // gets the number of parameters 
     $numArgs = func_num_args(); 
     $arg_list = func_get_args(); 
     // make decisions based on the arguments number 
     switch($numArgs){ 
      case "2":return $this->ConstructorWithTwoArgs($arg_list[0], $arg_list[1]); 
      case "10":return $this->ConstructorWithTenArgs($arg_list[0], $arg_list[1],$arg_list[2], $arg_list[3],$arg_list[4], $arg_list[5],$arg_list[6], $arg_list[7],$arg_list[8], $arg_list[9]); 
      default: 
       //Handle exception for method not existing with that many parrams 
       break; 
     } 
    } 
    //In order to log in we require minimum of user name and password 
    protected function ConstructorWithTwoArgs($userName, $password){ 
     $this->_userName = $userName; 
     $this->_password = $password; 
     $this->_login = "false"; 
    return $this; 
    } 
    //Checks users details and updates user details if valid 
    public function DoLogin(){ 
     $result = false; 
     // Check if userName and password exist in the db 
     $query = "SELECT * FROM SIT203Users WHERE USER_NAME = :userName AND PASSWORD = :password"; 
     // Create a new connection query 
     $ds = new Connection(); 
     $ds->parse($query); 
     $ds->setBindValue(':userName', $this->_userName); 
     $ds->setBindValue(':password', $this->_password); 
     $ds->execute(); 
     //User exists if rows are returned there will only be one as userName is unique 
     if($ds->getNextRow()){    
      $result = true; 
      $this->_login = "true"; 
      $this->_firstName = $ds->getRowValue("FIRST_NAME"); 
      $this->_lastName = $ds->getRowValue("LAST_NAME"); 
      $this->_email = $ds->getRowValue("EMAIL"); 
      $this->_phone = $ds->getRowValue("PHONE"); 
      $this->_addressStreet = $ds->getRowValue("ADDRESS_STREET"); 
      //Ensure all street details are obtained 
      if($ds->getRowValue("ADDRESS_STREET2")) 
       $this->_addressStreet .= $ds->getRowValue("ADDRESS_STREET2"); 
      $this->_addressCity = $ds->getRowValue("ADDRESS_CITY"); 
      $this->_addressState = $ds->getRowValue("ADDRESS_STATE"); 
      $this->_company = $ds->getRowValue("COMPANY"); 
    } 

     $ds->freeResources(); 
     $ds->close();  
     return $result;  
    } 
} 

지금이 클래스에서이를 직접 호출 잘 작동되도록 PHP 클래스를 사용

; http://www.deakin.edu.au/~jtparker/SIT203/xyz/flower_shop2/MyAccount.php?userName=JaieP&password=jp

<?php 
require_once('initialise.php'); 

// Need to Validate all feilds and remove unwanted text 
// The feilds to be tested are the $_REQUEST values 
$userName = Validation::validateString(isset($_REQUEST['userName'])?$_REQUEST['userName']:""); 
$password = Validation::validateString(isset($_REQUEST['password'])?$_REQUEST['password']:""); 
$remberMe = isset($_REQUEST['remberMe'])?$_REQUEST['remberMe']:""; 

// Create a new user 
$newUser = new Users($userName, $password); 
// Try and login 
$newUser->DoLogin(); 
if($newUser->getLogin() == "true") 
    { 
    $_SESSION['user'] = $newUser; 
    // Echo out the users details plus cart details for last 3 months 

    //test its working to here 
    //echo($newUser->toString()); 
    echo("Its working!!!"); 
} 
else 
    { 
    //echo("falseValue"); 
    echo($userName.$password.$remberMe.$newUser->getLogin().$newUser->getUserName().$newUser->DoLogin().$newUser->toString()); 
} 
?> 

하지만 난 _login 변수를 업데이트하고 왜 운동을 할 수없는 내 인생에 실패 아래의 코드를 사용하여 자바 스크립트 호출을 통해 그것을 사용하려고하면? 이 링크에서 볼 수 있듯이 ; http://www.deakin.edu.au/~jtparker/SIT203/xyz/flower_shop2/myaccount.html 매번 실패합니까? 사전에

어떤 아이디어를 많은 감사 Jaie

function TryLogin(){  
    try{ 
     // Get the userName and password supplied 
     var userName = document.getElementById("userName"); 
     var password = document.getElementById("password"); 

     // Get the remember me value 
     var rememberMe = document.getElementById("rememberMe"); 

     // Get the error feild 
     var errorDisplay = document.getElementById("submitError"); 
     // set to no error 
     errorDisplay.innerHTML = ""; 

     var documentMyAccount = document.getElementById("myAccount"); 

     // Submit details to server for verification if not empty 
     if(userName.value != "" && password.value != ""){ 
      // Now check via DB if username and password are valid 
      if (window.XMLHttpRequest) 
      { // code for IE7+, Firefox, Chrome, Opera, Safari 
       xmlhttp=new XMLHttpRequest(); 
      } 
      else 
      { // code for IE6, IE5 
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      } 

      xmlhttp.onreadystatechange=function() 
      { 
       if (xmlhttp.readyState==4 && xmlhttp.status==200) 
       { 
        // IF Response indicates a successful login 
        var myResponse = xmlhttp.responseText; 
        if(myResponse != "falseValue"){ 
         // set to nothing 
         documentMyAccount.innerHTML = ""; 
         // add php content 
         documentMyAccount.innerHTML = myResponse; 
        } 
        else{ 
         // Do not advise what details are incorrect, just that some combination is incorrect 
         errorDisplay.innerHTML = "Sorry those details are not correct"; 
        } 
       } 
      } 
      var submitString = "MyAccount.php?"; 
      submitString +="userName="+userName.value; 
      submitString +="&password="+password.value; 
      submitString +="&rememberMe="+rememberMe.checked?"true":"false"; 
      xmlhttp.open("GET",submitString,true); 
      xmlhttp.send(); 
     } 
     else{ 
      errorDisplay.innerHTML = "Not all details have been entered!"; 
     } 

    } 
    catch(error){ 
     alert(error.message); 
    } 
} 
+0

'xmlhttp.open' 호출 바로 전에'console.log (submitString)'의 출력은 무엇입니까? –

+0

굉장히 요점을 참조하십시오, 나는 그 문제를 생각합니다 ~~jtparker/SIT203/xyz/flower_shop2/MyAccount.php?userName=JaieP&password=jptrue 대답을 놓으십시오 그리고 당신이 그것을 못 박았 기 때문에 많은 감사합니다 :) – Jaie

답변

0
모든 것이 예상대로 전송되고 있으며, 그 해결할 수 있는지 당신은 단순히 당신의 AJAX에 의해 호출되는 최종 URL 무엇을 디버깅하고 확인해야

그것.

는 AJAX 호출하기 전에

console.log(submitString) 

을 시도하고 모든 것이 제대로 전송되는 경우에 당신은 알 수 있습니다.

+0

Many 감사!!!! – Jaie

관련 문제