U didnt finished query u need to know what u asking from database this way u made, its like u asked where username ?
and u need to ask where username from database is equal to username from login form
Code:
$check = ("SELECT username, passwort, rechte FROM user WHERE username");
With asking from database WHERE username
Here is tested code all works, and u need this 3 fields in database to works ( username, passwort, rechte )
Code:
//require_once ('/../var.php');
$db_link = mysqli_connect (
$mysqlhost,
$mysqluser,
$mysqlpass,
$mysqldata
);
// so first check login form if username and password is entered
if (isset($_POST['login'])) { // if login button is pressed
// check if username and password isset
if (isset($_POST['username']) && isset($_POST['passwort'])) {
// make variables for easier user
$username = trim($_POST['username']);
$passwort = trim($_POST['passwort']);
// if all fields are entered
if (!empty($username) && !empty($passwort)) {
// if fields are entered lets check if username and password is equal to username and password from login form
$check = mysqli_query($db_link, "SELECT username, password, rechte FROM `user` WHERE `username`='".mysqli_escape_string($db_link, $username)."' AND password='".mysqli_escape_string($db_link, $passwort)."'") or die('Database error !');
// if row (user) exists
if(mysqli_num_rows($check) == 1){
$row = mysqli_fetch_array($check, MYSQLI_BOTH);
// start session
$_SESSION['rechte'] = $row['rechte'];
$_SESSION['username'] = $row['username'];
$status = $_SESSION['rechte']; // this one is used for user status 0 or 1 or 2
$us = $_SESSION['username']; // username
// now u can check user status
if ($status == 2) {
include('example_with_rights.php')
}
else {
echo 'Permission Denied';
}
} else {
echo 'Invalid user data entered.';
}
} else {
echo "Please enter username and passwort";
}
}
}
And login form
Code:
<form action="" method="POST">
Username <input type="text" name="username"><br />
Passwort <input type="password" name="passwort"><br />
<input type="submit" name="login" value="Login">
</form>