Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Login system pager error?

Community Beginner ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

I've created a basic PHP login system as a personal project. I've finished all the pages but when I try and submit a username and password I get an error :

Fatal error: Call to a member function prepare() on a non-object in /home/(my username)/public_html/classes/Mysql.php on line 20

I've tinkered with it for a while but I haven't been able to find a solution, can anyone help me out?

<?php

require_once'includes/constants.php';

class Mysql {

          private $conn;

 

          function __contruct() {

                    $this->conn = new mysql (DB_SERVER, DB_USER, DB_PASSWORD,DB_NAME) or

                              die('Problem connecting to 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;

                              }

 

                    }

 

          }

}

TOPICS
Server side applications

Views

1.1K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

Can you give us an idea of your file hierarchy?

Apart from that, the first thing I noticed is you're missing ()brackets in your require statement.

Try require_once('includes/constants.php');

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2012 Sep 15, 2012

Copy link to clipboard

Copied

Sudarshan Thiagarajan wrote:

Apart from that, the first thing I noticed is you're missing ()brackets in your require statement.

Try require_once('includes/constants.php');

That makes no difference. The parentheses are optional with include and require.

There are a couple of problems in the class definition here:

function __contruct() {

                    $this->conn = new mysql (DB_SERVER, DB_USER, DB_PASSWORD,DB_NAME) or

                              die('Problem connecting to database');

          }

__construct() is misspelled.

Also it should be new mysqli.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2012 Sep 15, 2012

Copy link to clipboard

Copied

That makes no difference. The parentheses are optional with include and require.

Gosh, What was I thinking?! Thanks David for the correction. Appreciate it!

Sorry, Tyharo - if I misguided you.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2012 Sep 15, 2012

Copy link to clipboard

Copied

          function __contruct() {

                    $this->conn = new mysql (DB_SERVER, DB_USER, DB_PASSWORD,DB_NAME) or

                              die('Problem connecting to database');

          }

I changed it to whats shown above but now i get a 503 error saying the server is temorarly busy. I can login into my hosting, view my mysql databases, and login to phpmyadmin just fine; is this on my providers side or is my code causing this error?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2012 Sep 15, 2012

Copy link to clipboard

Copied

LATEST

David mentioned earlier you've misspelled 'construct'. Your code reads 'contruct.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines