2

I'm new to php and I am trying to create a member system for my website. I seem to get an error on line 9 ("public function__construct(){") saying 'syntax error, unexpected T_STRING, expecting T_VARIABLE'. I would appreciate any help on why I am getting this error. Thanks.

My code:

<?php 

include_once('connection.php')

class User {

    private $db;

    public function__construct(){    
        $this->db = new connection ();
        $this->db = $this->db->dbConnect();
    }

    public function Login($name, $pass){
        if (!empty($name) && !empty($pass) ) {
            $st = $this->db->prepare("select * from users where name=? and pass=?");
            $st->bindParam(1, $name);
            $st->bindParam(2, $pass);
            $st->execute();

            if ($st->rowCount() == 1) {
                echo "user verified access granted";
            }else{
                echo "Incorrect username or password";
            }

        }else{
            echo "Please enter username and password";
        }
    }
}

 ?>
1
  • 4
    Missing a space after function in public function__construct(){
    – j08691
    Nov 29, 2013 at 17:55

3 Answers 3

4

I see two possible errors :

public function __construct() ... 

and next one is :

replace 1 , 2 while binding with '1' and '2'

2

The exact same problem faced my me. My mistake was to omit the space in function__construct(){} between the function keyword and the double underscore. One more thing you have to take care of regarding this is that you must attach curly braces to the function sign or ().

0

try function _construct() instead of function_construct()

1
  • 1
    Note: you should use 2 underscores Nov 29, 2013 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.