運行此文件時使用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);
?>
爲什麼這個被標記的Android? –
請仔細閱讀錯誤處理,它的語法錯誤使用'$ this'在第20行 – gaurav
也用於密碼散列使用[password_hash](http://php.net/manual/en/function.password-hash.php)而不是'md5' – gaurav