Hallo,
ich versuche meine Login-Seite zum laufen zu bringen aber ich kriege keinen Fehler angezeigt. Ich gaube etwas in der getData Methode in der login.php läuft falsch. Ich habe versuchte $ergebnis mit var_dump() auszugeben aber es kommt nix raus!
loginConroller.php:
login.php:
database2.php:
ich versuche meine Login-Seite zum laufen zu bringen aber ich kriege keinen Fehler angezeigt. Ich gaube etwas in der getData Methode in der login.php läuft falsch. Ich habe versuchte $ergebnis mit var_dump() auszugeben aber es kommt nix raus!
loginConroller.php:
PHP-Code:
<?php
error_reporting(-1);
ini_set('display_errors', 1);
if (isset($_POST['submit']) AND $_POST['submit']== 'Login') {
$username = $_POST['username'];
$password = $_POST['password'];
try{
include "./models/login.php";
$login = new Login($username, $password);
if ($login== TRUE) {
session_start();
$_SESSION['username'] = $username;
header('Location: index.php');
}
}catch(Exception $exc ){
echo $exc->getMessage();
}
}
?>
PHP-Code:
<?php
class Login
{
private $username;
private $password;
private $cxn; // Database object.
function __construct($username, $password)
{
// Set data
$this->setData($username, $password);
// connect to db
$this->connectToDb();
//get Data
$this->getData();
}
private function setData($username, $password){
$this->username = $username;
$this->password = $password;
}
private function connectToDb(){
include 'models/database2.php';
$vars = "include/vars.php";
$this->cxn = new Database2($vars);
}
private function getData(){
$query ="SELECT 'username', 'password' FROM 'users' WHERE 'username' = '$this->username'
AND 'password' = '$this->password'";
$result = mysqli_query($this->cxn->db, $query) or die(mysql_error());
var_dump($result);
$num_row = mysqli_num_rows($result);
if ($num_row>1) {
return TRUE;
}else{
throw new Exception("The query was not successful!");
}
}
function close(){
$this->cxn->close_connect();
}
}
?>
PHP-Code:
<?php
class Database2{
private $host;
private $user;
private $password;
private $database;
public $db;
function __construct($filename){
if(is_file($filename)){
include $filename;
}else{
throw new Exception("Error Processing Request");
}
$this->host = $host;
$this->user = $user;
$this->password =$password;
$this->database =$database;
$this->connect();
}
public function connect(){
// connect to the server.
$this->db = new mysqli($this->host, $this->user, $this->password);
if ($this->db->connect_errno) {
die("We are sorry, you could not be connected to the server,
plaese check your connection setting!");
}else{
echo "You are connected to the database";
}
}
public function close_connect(){
mysql_close();
}
}
?>
Kommentar