I am creating an app and I want that the buttons appear based on your $job. There are 4 jobs, which are all in mysql databases:
- student
- teacher
- staff
- principal,
The signup button can only be seen by teacher, staff and principal.
But It doesn't work.
Here is my code:
<?php
session_start();
include("connection.php");
include("functions.php");
$user_data = check_login($con);
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$job = $_POST['job'];
$query = "select * from users where job = '$job' limit 1";
$result = mysqli_query($con, $query);
$user_job = mysqli_fetch_assoc($result);
if (in_array($user_job, ['teacher', 'staff', 'principal'])) {
?>
<body>
<a href="signup.php">
<button>Signup Student</button>
</a>
</body>
<?php
}
}
?>
<!DOCTYPE html>
<html>
<title>
NetPlat
</title>
<head>
</head>
<body>
<a href="login.php">
<button id="button">Logout</button>
</a><br><br>
</body>
</html>
I've also done this:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$job = mysqli_real_escape_string($con, $_POST['job']);
$user_job = $con->prepare("SELECT * FROM `users` WHERE job = '$job'");
$user_job->bind_param('s', $job); // 's' specifies the variable type => 'string'
$user_job->execute();
$result = $user_job->get_result();
while ($row = $result->fetch_assoc()) {
if(in_array($user_job, ['teacher', 'staff', 'principal'])){
?>