Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:43:26+00:00 2026-06-14T11:43:26+00:00

I’m trying to create a simple login with php and mysqli but keep receiving

  • 0

I’m trying to create a simple login with php and mysqli but keep receiving the error:
Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\web2\database.php on line 107

database.php

 <?php
class Database 
{ 
 public $server = "localhost";
 public $database = "database"; 
 public $user = "root"; 
 public $password = ""; 
 public $row;
 public $result;
 public $sqlExtra = " ORDER BY firstname ASC";
 public $dbLocalHost;





 //call connection method upon constructing 
 public function __construct(){
  $this->createConnection(); 
 }

 //connection to the database
 public function createConnection() 
    { 
     $this->dbLocalhost = new mysqli($this->server, $this->user, $this->password, $this->database)
                or die("could not connect:");


      //mysql_select_db($this->database)
       //
       //  or die("Could not find the database: ".mysql_error());



 } 



    function verifyLogin($email, $password) {

        $query = "SELECT *
                FROM admint
                WHERE email = ?
                AND password = ?
                LIMIT 1";

 107.               $statement = $this->dbLocalHost->prepare($query);
        if($statement) {
            $statement->bind_param('ss', $email, $password);
            $statement->execute();

            if($statement->fetch()) {
                $statement->close();
                return true;    
            }
            else {
                return false;
            }
        }

    }

    function addElement($table, $firstName, $lastName, $email, $mobile, $password,
                            $faculty, $campus) {



        $query = "INSERT INTO $table (first_name, last_name, email, mobile, password, faculty, campus_location) 
                VALUES('$firstName', '$lastName','$email','$mobile',
                '$password','$faculty','$campus');";

        if($this->connection->query($query)) {
            header('location: regConfirm.php');     
        }

    }


} 

?>

login.php

 <?php
session_start();

require_once 'admin.php';
$admin = new Admin();

if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {
    $admin->logOut();   
}


if($_POST && !empty($_POST['email']) && !empty($_POST['password'])) {

    $valid = $admin->validateUser($_POST['email'], $_POST['password']);

    if($valid) {
        header("location: index.php");  
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>

<body>
<div id="login">
    <form method="post" action="">
    <h1>Admin Login</h1>
    <p>
        Email: 
        <input type="email" name="email" />
    </p>

    <p>
        Password: 
        <input type="password" name="password" />
    </p>

    <p>
        <input type="submit" value="Login" name="Submit" />
    </p>

    </form>

</div>

</body>
</html>

admin.php

    <?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin
 *
 * @author Matt
 */
require 'database.php';
class admin {

   function logOut() {
        if(isset($_SESSION['status'])) {
            unset($_SESSION['status']);

            if(isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time() - 1000);
                session_destroy();  
            }
        }
    }

    function validateUser($email, $password) {
        $db = new Database();

        $verified = $db->verifyLogin($email, $password);

        if($verified) {
            $_SESSION['status'] = 'authorised';
            //header("location: index.php");
            return true;    
        }
        else {
            return false;   
        }
    }

    function confirmAdmin() {
        session_start();
        if($_SESSION['status'] != 'authorised')
            header("location: login.php");  
    }
}

?>

sorry to be a bother, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:43:27+00:00Added an answer on June 14, 2026 at 11:43 am

    Typo:

               $statement = $this->dbLocalHost->prepare($query);
                                          ^--- should be an "h"
    

    php variable names are case-sensitive. In your connection method, you use dbLocalhost with a small h.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.