so i have made a new login system that works but i need a little help with a few things. so i'm making a website where you can order stuff. there are 2 kind of buyers. one of them: regular buyers. they can't log in and buy their drinks for a regular price. the second one: store owners: they log in and buy their products for a discount BUT have to atleast buy 10 products before they can check out. then there is one other person that can log in and that is the admin. I have been struggeling with this this for days now but: how do I create this? how do I let my code know that if user == admin then ,for example, add a link in the navbar for the order list. or if user == store owner then put minimal of 10 items before checkout. and if user == not logged in then still allow user to buy products?
i just noticed that it might be important to tell that you can't register your own account. you have to send the admin a email and they will have to create a account for you with a random password. im still working on that one but because i don't know how to let the code know that certian users are different then i can't really work on that
this is my db with a test admin account:
login script
<?php
if (!isset($_SESSION)) { session_start(); }
include("config.php");
include "navbar.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>login</title>
</head>
<style>
#login{
/* display: flex;
justify-items: center; */
padding: 10px;
}
input[type=text], input[type=password] {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
</style>
<body>
<div id="login">
<!-- die form name shit moest er nog bij ik denk wegens de post ofzo in iedergeval werkt de knop nu -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<h2>Login</h2>
<br>
<a>Dit is alleen voor bedrijven en admin</a>
<br>
<label>email</label><br>
<input type="text" placeholder="email" name="email" class="email" required />
<br>
<label>wachtwoord</label><br>
<input type="password" placeholder="wachtwoord" name="wachtwoord" class="wachtwoord1" required ><br>
<input type="submit" value="Log In" class="log" name="log"/>
</form>
</div>
</body>
</html>
<?php
if ( !isset($_POST['email'], $_POST['wachtwoord']) ) {
exit('Please fill both the username and password fields!');
}
if ($stmt = $conn->prepare('SELECT * FROM users WHERE email = ?')) {
$email = $_POST['email'];
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$resultaat = $stmt->bind_result($id, $username, $email, $password, $rol);
$stmt->fetch();
if ($_POST['wachtwoord'] === $password) {
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $_POST['email'];
$_SESSION['id'] = $id;
echo 'Welcome ' . $_SESSION['name'] . '!';
} else {
echo 'Incorrect email and/or password!';
}
} else {
echo 'Incorrect email and/or password!';
}
$stmt->close();
}
?>
and this is my store page: I still have to do some work on that one such as creating a working way to order a few products and to put them in a shopping bag
<?php
include "navbar.php";
?>
<?php
//if logged in
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
echo "Welkom Gast";
exit;
}
?>
<html>
<head>
<style>
h1 {
display: flex;
justify-content: center;
}
table {
display: flex;
justify-content: center;
}
td {
display: flex;
justify-content: center;
}
#winkelmandje_knop{
display: none;
}
#winkelmandje_knop + label{
font-size: 3.5rem;
}
#winkelmandje{
text-align: center;
z-index: 3;
position: fixed;
bottom: 40%;
right: 0;
left: 0;
height: 20%;
visibility: hidden;
width: 100%;
background-color: #C2F98E;
border-radius: 5%;
opacity: 0.9;
filter: alpha(opacity=9);
}
#rijen{
visibility: hidden;
padding: 0;
margin: 0;
width: 100%;
}
'
form > .aantal{
width: 30px;
height: 20px;
margin-left: auto;
margin-right: auto;
border: solid 1px gray;
}
</style>
</head>
<body>
<div class="products">
<div class="productContainer">
<h1 id="banner">ALL ITEMS</h1>
<h2 id="testing name remembering">
<?php
if ($_SESSION['loggedin'] == false) {
echo "welcome gast";
}else{
echo 'Welcome ' . $_SESSION['name'] . '!';
}
?>
</h2>
<?php
include "config.php";
$vraag = "SELECT Naam, prijs, voorraad FROM bier";
$result = $conn->query($vraag);
?>
<table>
<?php
$loop = 0;
foreach ($result as $row) :
?>
<tr>
<td>Naam: <?= $row["Naam"]; ?></td>
<td>Prijs: <?= $row["prijs"]; ?></td>
<td>voorraad: <?= $row["voorraad"]; ?></td>
<td>Aantal: <?php echo "<input class='aantal' type='text' style='width: 10%;' value='0' />";?>
</tr>
<?php
$loop++;
endforeach;
echo "<input type='hidden' name='loop' id='loop' value='".$loop."'/>";
?>
</table>
<!--winkelmandje aan/uit -->
<input type="checkbox" name="winkelmandje_knop" id="winkelmandje_knop" onclick="javascript:schowWinkelmandje();" class="icon" value="🛍" />
<label for="winkelmandje_knop">🛍 </label>
<br>
<div class="icon_container">
<input type="submit" class="icon" id="submit" name="submit" value="→" />
</div>
<br>
</form>
</div>
<!-- winkelmandje -->
<div id="winkelmandje">
<div id="rijen"></div>
<!-- java word moeilijk want ik snao daar helemaal niks van -->
<input type="checkbox" id="winkelmandje_knop" onclick="javascript:showWinkelmandje();" class="icon" value="X" />
<label for="winkelmandje_knop" style="color: red;">⊝</label>
</body>
</html>