Note that there are some explanatory texts on larger screens.

plurals
  1. POPDO prepare() error
    primarykey
    data
    text
    <p>I've got this, error (And yes, I've searched for it, but couldn't find any solutions).</p> <pre><code>Fatal error: Call to a member function prepare() on a non-object in C:\inetpub\oop\_classes\class.users.php on line 19 </code></pre> <p>Class.users.php:</p> <pre><code>&lt;?php include_once("class.db.php"); class Users { protected $vpanel; public function __construct() { $this-&gt;vpanel = new Database(); $this-&gt;vpanel = $this-&gt;vpanel-&gt;dbConnection(); } public function Login($username, $password) { if(!empty($username) || !empty($password)) { $sth = $this-&gt;vpanel-&gt;prepare("SELECT * FROM `users` WHERE `username` = ? AND `password` = ?"); $sth-&gt;bindParam(1, $username); $sth-&gt;bindParam(2, $password); $sth-&gt;execute(); if($sth-&gt;rowCount() == 1) { echo "Correct details."; } else { echo "Incorrect details."; } } else { echo "Fill out all the fields."; } } } ?&gt; </code></pre> <p>class.db.php:</p> <pre><code>&lt;?php class Database { public function dbConnection() { $dbhost = "localhost"; $dbname = "DBNAME"; $dbusername = "DBUSERNAME"; $dbpass = "PASSWORD"; try { $this-&gt;vpanel = new PDO("mysql:host".$dbhost.";dbname=".$dbname."", $dbusername, $dbpass); $this-&gt;vpanel-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo $e-&gt;getMessage() . " (class.core.php) "; } } } ?&gt; </code></pre> <p>global.php:</p> <pre><code>&lt;?php session_start(); ini_set('display_errors', 1); require_once $_SERVER['DOCUMENT_ROOT'] . "/_includes/config.php"; try { $vpanel = new PDO("mysql:host".$Config['db']['host'].";dbname=".$Config['db']['dbname']."", $Config['db']['uname'], $Config['db']['pass']); } catch(PDOException $e) { echo $e-&gt;getMessage(); } require_once $_SERVER['DOCUMENT_ROOT'] . "/_classes/class.db.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/_classes/class.users.php"; $database = new Database(); $users = new Users(); ?&gt; </code></pre> <p>I don't know whats wrong, I'm new to the PDO methods (and some of the OOP)... so... thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload