-1

I have a problem when i enter login details i get this error

Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\Remake Login Page\Classes\Mysql.php on line 22

Code of Mysql.php:

<?php

require_once 'includes/constants.php';

class Mysql {
private $conn;

function _construct() {
    $this->$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die 
                  ('There was a problem connecting to the database');
}

function verify_Username_and_Pass($un, $pwd) {


    $query = "SELECT *
            FROM users
            WHERE username = ? AND password = ?
            LIMIT 1";


    if($stmt = $this->conn->prepare($query)) {
        $stmt->bind_param('ss', $un, $pwd);
        $stmt->execute();


        if($stmt->fetch()) {
            $stmt->close();
            return true;
        }
    }

}

}

Hope someone can help me.

Thanks in advance.

Roy M J
  • 6,926
  • 7
  • 51
  • 78
user2737015
  • 79
  • 1
  • 1
  • 5

3 Answers3

4

A constructor methods starts with double underscore. A method with a single underscore is just normal function name.

Try this:

function __construct() {
    $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database');
}
Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Jasmin Mistry
  • 1,459
  • 1
  • 18
  • 23
3

Your construct function needs two underscores.

Jordi Jolink
  • 461
  • 3
  • 7
2

Your constructor should say $this->conn rather than $this->$conn.

Annika Backstrom
  • 13,937
  • 6
  • 46
  • 52