Metorium Posted October 25, 2014 Share Posted October 25, 2014 (edited) 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 October 25, 2014 by mac_gyver code tags when posting code please Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 25, 2014 Share Posted October 25, 2014 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). Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 25, 2014 Share Posted October 25, 2014 For the sake of others having similar issues in the future, let's keep the discussion in the thread. Read up on PDO here. You'll want to look at the __construct() function I directly linked to, as well as prepare(), bind(), query() and execute(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.