Я создал раскрывающееся меню для регистрации, где, когда новый пользователь хочет зарегистрировать свою учетную запись, он заполняет всю необходимую информацию, включая выбор типа пользователя.
Существует уровень параметра в форма регистрации. Каким-то образом после того, как пользователь зарегистрировался, база данных не сохранила уровень пользователя, вместо этого она сохранила «0» внутри базы данных.
<div class="input-group">
<label>Type of user</label>
<select name="level" value="option">
<option value=""> Select...</option>
<option value=1>Student</option>
<option value=2>Supervisor</option>
<option value=3>Admin</option>
</select>
</div>
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$name = mysqli_real_escape_string($db, $_POST['name']);
$matric_number = mysqli_real_escape_string($db, $_POST['matric_number']);
$level = mysqli_real_escape_string($db, $_POST['level']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
// form validation: ensure that the form is correctly filled ...
// by adding (array_push()) corresponding error unto $errors array
if (empty($name)) { array_push($errors, "Name is required"); }
if (empty($matric_number)) { array_push($errors, "Matric number is required"); }
if (empty($level)) { array_push($errors, "Level is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
// first check the database to make sure
// a user does not already exist with the same name or matric number
$user_check_query = "SELECT * FROM authentication WHERE name='$name' OR matric_number='$matric_number' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['name'] === $name) {
array_push($errors, "name already exists");
}
if ($user['matric_number'] === $matric_number) {
array_push($errors, "matric_number already exists");
}
}
// Finally, register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);//encrypt the password before saving in the database
$query = "INSERT INTO authentication (name, matric_number, level, password)
VALUES('$name', '$matric_number','&level', '$password')";
mysqli_query($db, $query);
$_SESSION['name'] = $name;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}