Guest User

Untitled

a guest
Mar 21st, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1.  login.php
  2.  <?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(); } } ?>
  3.  
  4. database.php
  5. <?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(); } } ?>
  6. vars.php
  7.  <?php $host = "localhost"; $user = "root"; $password = ""; $database = "journeyholic"; ?>
  8. the errors are Warning: mysqli_query() expects at least 2 parameters, 1 given in C:
  9. and
  10.  Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, string given in C:
Add Comment
Please, Sign In to add comment