Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login.php
- <?php class Login { private $username; private $password; private $cxn; function __construct($username,$password) { $this->setData($username, $password); $this->connectToDb(); $this->getData(); } private function setData($username,$password){ $this->username = $username; $this->password = $password; } private function connectToDb(){ include 'models/Database.php'; $vars = "include/vars.php"; $this->cxn = new Database($vars); } function getData(){ $query = "SELECT * FROM `users` WHERE `username` = '$this->username' AND `password` = '$this->password'"; $sql = mysqli_query($query); if(mysqli_num_rows($query)>0) { return TRUE; } else{ throw new Exception("Username Or Password Is Invalid,Please Try Again"); } } function close(){ $this->cxn->close(); } } ?>
- database.php
- <?php class Database { private $host; private $user; private $password; private $database; function __construct($filename) { if (is_file($filename)) include $filename; else throw new Exception("Error"); $this->host = $host; $this->user = $user; $this->password = $password; $this->database = $database; $this->connect(); } private function connect() { if (!mysqli_connect($this->host, $this->user, $this->password)) throw new Exception("Error:Not Connected To The Server"); if (!mysqli_select_db(mysqli_connect($this->host, $this->user, $this->password), $this->database)) throw new Exception("Error:No Database Selected"); } function close() { mysqli_close(); } } ?>
- vars.php
- <?php $host = "localhost"; $user = "root"; $password = ""; $database = "journeyholic"; ?>
- the errors are Warning: mysqli_query() expects at least 2 parameters, 1 given in C:
- and
- Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, string given in C:
Add Comment
Please, Sign In to add comment