Jump to content

When i click login it says error


Metorium

Recommended Posts

When i press login i get Fatal error: Call to a member function query() on a non-object in /home/a5347792/public_html/login.php on line 15

<?php

$dbConnection['username'] = "root";
$dbConnection['password'] = "";
$dbConnection['host'] = "localhost";
$dbConnection['db'] = "joke";


if(isset($_POST['rbLgn'])) {
  $login = true;
  if(isset($_POST['username'])) { $username = $_POST['username']; }
  if(isset($_POST['password'])) { $password = $_POST['password']; }
  if(isset($username) && isset($password)) {
    $query = $db->query("SELECT * FROM `users` WHERE `username`='{$username}' AND `password`='{$password}' LIMIT 1");
    if($query->num_rows > 0) {
      echo "User found - logging in.";
    }
    else
    {
      echo "User not found, credentials: " . $username . " | " . $password;
    }
  }
}
?>
Edited by mac_gyver
code tags when posting code please
Link to comment
Share on other sites

The variable $db isn't instantiated anywhere before you try to use it. You'll need to create a $db object using the credentials you put in the $dbConnection array. Also, please use code tags when posting code (the '<>' button on the editor).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.