0

i am getting an error when running this file using Postman error is "Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\wamp64\www\Android\include\DbOperations.php on line 20"

For more details check this link:

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

File 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)){
     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();
   execute->store_result();
   return $stmt->num_row > 0;
  }
 }

?>

File registerUser.php

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

$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){
 if(
  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'])
  ){
  //operate the data further

  $db = new DbOperations();

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

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

echo json_encode($response);

?>
  • why this is tagged Android?! – Atef Hares Feb 26 '17 at 06:12
  • 2
    Please read error care fully, it's syntax error use `$this` on line 20 – gaurav Feb 26 '17 at 06:15
  • Also for password hashing use [password_hash](http://php.net/manual/en/function.password-hash.php) instead of `md5` – gaurav Feb 26 '17 at 06:31
  • sorry for adding tag Android... and thanks gaurav. – SAMEER RAJPAL Feb 26 '17 at 06:45
  • @gaurav Hi! now i am getting this error "Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\wamp64\www\Android\include\DbOperations.php on line 39" in isUserExist Function "execute->store_result();" i changed it to "$stmt->store_result();" now getting this error [dropbox.com/s/m0ngx8hqy6vr3t8/Untitled.png?dl=0] – SAMEER RAJPAL Feb 26 '17 at 09:44

1 Answers1

0

You forgot to add $ sign

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;
        }
    }

?>
B. Desai
  • 16,414
  • 5
  • 26
  • 47
  • Hi! now i am getting this error "Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\wamp64\www\Android\include\DbOperations.php on line 39" in isUserExist Function "execute->store_result();" i changed it to "$stmt->store_result();" now getting this error [dropbox.com/s/m0ngx8hqy6vr3t8/Untitled.png?dl=0] – SAMEER RAJPAL Feb 26 '17 at 09:47
  • Thanks bro... thank you Very much. i am just a newbie to scripting. thanks a lot it's working now. – SAMEER RAJPAL Feb 26 '17 at 09:59