2017-02-26 44 views
0

運行此文件時使用Postman錯誤是「解析錯誤:語法錯誤,意外' - >'(T_OBJECT_OPERATOR)在C:\ wamp64 \ www \ Android \ include \ DbOperations.php第20" 行唯一身份證註冊檢查腳本不起作用

有關詳情,請點擊此鏈接:

https://www.dropbox.com/s/jecshgs34ra50qi/Untitled.jpg?dl=0

文件DbOperations.php

<?php 
 

 
\t class DbOperations{ 
 

 
\t \t private $con; 
 

 
\t \t function __construct(){ 
 

 
\t \t \t require_once dirname(__FILE__).'/DbConnect.php'; 
 

 
\t \t \t $db = new DbConnect(); 
 

 
\t \t \t $this->con = $db->connect(); 
 
\t \t 
 
\t \t } 
 

 
\t \t /*CRUD -> c -> CREATE */ 
 

 
\t \t public function createUser($name, $surname, $username, $user_pass, $address, $pin, $mail, $phone){ 
 
\t \t \t if(this->isUserExist($username,$mail,$phone)){ 
 
\t \t \t \t \t return 0; 
 
\t \t \t }else{ 
 
\t \t \t \t $password = md5($user_pass); 
 
\t \t \t \t $stmt = $this->con->prepare("INSERT INTO `user_data` (`name`, `surname`, `username`, `password`, `address`, `pin`, `mail`, `phone`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); 
 
\t \t \t \t $stmt->bind_Param("ssssssss",$name,$surname,$username,$password,$address,$pin,$mail,$phone); 
 

 
\t \t \t \t if($stmt->execute()){ 
 
\t \t \t \t \t return 1; 
 
\t \t \t \t }else{ 
 
\t \t \t \t \t return 2; 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t private function isUserExist($username, $mail, $phone){ 
 
\t \t \t $stmt = $this->con->prepare("SELECT id FROM user_data WHERE username = ? or mail = ? or phone = ?"); 
 
\t \t \t $stmt->bind_param("sss", $username, $mail, $phone); 
 
\t \t \t $stmt->execute(); 
 
\t \t \t execute->store_result(); 
 
\t \t \t return $stmt->num_row > 0; 
 
\t \t } 
 
\t } 
 

 
?>

文件registerUser.php

<?php 
 
require_once '../include/DbOperations.php'; 
 

 
$response = array(); 
 

 
if($_SERVER['REQUEST_METHOD']=='POST'){ 
 
\t if(
 
\t \t isset($_POST['reg_name']) and isset($_POST['reg_surname']) and isset($_POST['reg_username']) and isset($_POST['reg_password']) and isset($_POST['reg_address']) and isset($_POST['reg_pin']) and isset($_POST['reg_mail']) and isset($_POST['reg_phone']) 
 
\t \t){ 
 
\t \t //operate the data further 
 

 
\t \t $db = new DbOperations(); 
 

 
\t \t $result = $db->createUser(\t $_POST['reg_name'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_surname'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_username'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_password'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_address'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_pin'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_mail'], 
 
\t \t \t \t \t \t \t \t \t $_POST['reg_phone'] 
 
\t \t \t \t \t \t \t \t); 
 
\t \t if($result == 1){ 
 
\t \t \t $response['error'] = false; 
 
\t \t \t $response['message'] = "User register successfully"; 
 
\t \t }elseif($result == 2){ 
 
\t \t \t $response['error'] = true; 
 
\t \t \t $response['message'] = "Something wrong, try again"; 
 
\t \t }elseif ($result == 0) { 
 
\t \t \t $response['error'] = true; 
 
\t \t \t $response['message'] = "User already register"; 
 
\t \t } 
 

 
\t }else{ 
 
\t \t $response['error'] = true; 
 
\t \t $response['message'] = "Required fields are missing"; 
 
\t } 
 
}else{ 
 
\t $response['error'] = true; 
 
\t $response['message'] = "Invalid Request"; 
 
} 
 

 
echo json_encode($response); 
 

 
?>

+0

爲什麼這個被標記的Android? –

+2

請仔細閱讀錯誤處理,它的語法錯誤使用'$ this'在第20行 – gaurav

+0

也用於密碼散列使用[password_hash](http://php.net/manual/en/function.password-hash.php)而不是'md5' – gaurav

回答

0

你忘了添加$標誌

DbOperations.php

<?php 

    class DbOperations{ 

     private $con; 

     function __construct(){ 

      require_once dirname(__FILE__).'/DbConnect.php'; 

      $db = new DbConnect(); 

      $this->con = $db->connect(); 

     } 

     /*CRUD -> c -> CREATE */ 

     public function createUser($name, $surname, $username, $user_pass, $address, $pin, $mail, $phone){ 
      if($this->isUserExist($username,$mail,$phone)){ //<--------change this 
        return 0; 
      }else{ 
       $password = md5($user_pass); 
       $stmt = $this->con->prepare("INSERT INTO `user_data` (`name`, `surname`, `username`, `password`, `address`, `pin`, `mail`, `phone`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); 
       $stmt->bind_Param("ssssssss",$name,$surname,$username,$password,$address,$pin,$mail,$phone); 

       if($stmt->execute()){ 
        return 1; 
       }else{ 
        return 2; 
       } 
      } 
     } 

     private function isUserExist($username, $mail, $phone){ 
      $stmt = $this->con->prepare("SELECT id FROM user_data WHERE username = ? or mail = ? or phone = ?"); 
      $stmt->bind_param("sss", $username, $mail, $phone); 
      $stmt->execute(); 
      $stmt->->store_result(); 
      return $stmt->num_rows > 0; 
     } 
    } 

?> 
+0

謝謝,我明白了。 –

+0

嗨!現在我在isUserExist函數「execute-> store_result()中得到這個錯誤」解析錯誤:語法錯誤,意外的' - >'(T_OBJECT_OPERATOR)在C:\ wamp64 \ www \ Android \ include \ DbOperations.php 39行「 ;」我將它改爲「$ stmt-> store_result();」現在得到這個錯誤[dropbox.com/s/m0ngx8hqy6vr3t8/Untitled.png?dl=0] –

+0

謝謝兄弟...非常感謝。我只是一個新手腳本。非常感謝它現在正在工作。 –