Skip navigation
Tyharo
Currently Being Moderated

Login system pager error?

Sep 14, 2012 3:36 PM

Tags: #problem #help #error #website #php #server #database #mysql #form #login #system #page #dreamweaver_cs5.5 #execute

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;

                              }

 

                    }

 

          }

 

 

}

 

 
Replies
  • Sudarshan Thiagarajan
    3,729 posts
    Oct 15, 2010
    Currently Being Moderated
    Sep 14, 2012 10:53 PM   in reply to Tyharo

    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');

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 15, 2012 6:39 AM   in reply to Sudarshan Thiagarajan

    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.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    3,729 posts
    Oct 15, 2010
    Currently Being Moderated
    Sep 15, 2012 10:02 AM   in reply to David_Powers

    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.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    3,729 posts
    Oct 15, 2010
    Currently Being Moderated
    Sep 15, 2012 11:06 PM   in reply to Tyharo

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points