所以我得到同样的错误,这让我疯了。
布尔(假)
注意:尝试在第21行的/var/www/public/database.php>中获取非对象的属性
nicht eingeloggt
虽然选择正确,但似乎结果始终为false。我是PHP和数据库的新手,所以我还没有深入研究它。我希望有人能帮助我。
database.php
<?php
class dbanbindung {
private $connection;
function __construct(){
$this->connection = new mysqli("localhost", "wt1p2_nutzer", "12345678", "wt1p2");
if($this->connection->connect_error){
echo die($this->connection->connect_error);
}
}
public function login($mail, $pwd) {
$result = $this->connection->query("SELECT pwd FROM user WHERE mail ='$mail'");
var_dump($result);
// line 20
if ($result->num_rows == 1) {
$zeile = $result->fetch_assoc();
$pw_result = $zeile["pwd"];
if (strcmp($pw_result, $pwd) == 0) {
return TRUE;
} else {
return FALSE;
}
}
function __destruct(){
$this->connection->close();
}
}
?>
login.php
<?php
session_start();
require ('database.php');
$datenbank = new dbanbindung();
$mail = $_POST["mail"];
$pwd = hash('SHA512',$_POST["password"]);
$login = $datenbank->login($mail,$pwd);
if ($login) {
echo ("login erfolgreich");
$_SESSION["mail"] = $mail;
}
else {
echo "nicht eingeloggt";
// header("refresh:5;index.php#login");
}
?>
index.php
<form method="POST" action="login.php">
<table border="0" id="table">
<tr>
<th>Mailadresse:</th>
<th><input type="text" name="mail" value="" placeholder="example@example.com"></th>
</tr>
<tr>
<th>Passwort:</th>
<th><input type="password" name="password" value="" placeholder="******"></th>
</tr>
</table>
<br />
<input type="submit" value="Login">
</form>