Вам просто нужно написать точный тип пользователя, попробуйте этот код:
<?php
if(isset($_POST['submit'])) {
// Make sure to change "username" "password" "database"
$conn = mysqli_connect("localhost", "username", "password", "database");
$username = $_POST['username'];
$password = $_POST['password'];
$type = $_POST['usertype'];
$query="SELECT * FROM user_level WHERE username='$username' and password='$password' and type='$type'";
$result=mysqli_query($conn,$query);
// Just use the if statement, it will test if a user exist with these infromation or not
if( $row = mysqli_fetch_array($result) ) {
// Now we are sure that we entered a right information and there a user, you just need to test the type using the switch statement
switch ($type) {
case "admin" :
header("Location: admin_mainpage.php");break;
case "landlord" :
header("Location: LO_mainpage.php");break;
case "customer" :
header("Location: Customer_mainpage.php");break;
}
}
}
?>
<form method="post">
<div class="form-group">
<label for="inputUsername">Username</label>
<input type="text" class="form-control" name="username" placeholder="username" required>
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="user_type">
<table>
<tr>
<td>User Type </td>
<td>
<select name="usertype" id="type" required>
<option value="" selected> Select user type</option>
<option value="customer" >Customer</option>
<option value="landlord" >Landlord</option>
<option value="admin" >Admin</option>
</select>
</td>
<td>
<button type="submit" name="submit" class="btn btn-primary">Login</button>
</td>
</tr>
</table>
</form>
Это таблица sql:
DROP TABLE IF EXISTS `user_level`;
CREATE TABLE `user_level` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
`type` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `user_level` (`id`, `username`, `password`, `type`) VALUES
(1, 'mac', '123', 'admin'),
(2, 'krisha', '123', 'customer'),
(3, 'Haris', '123', 'landlord');