How can one handle user registration approval by an administrator in PHP?
When a user registers on a website, their registration typically needs to be approved by an administrator before they can access the site. One way to handle this is to add a 'status' field in the user database table, where the status is set to 'pending' upon registration. The administrator can then change the status to 'approved' once they review and approve the registration.
// Assuming you have a users table with fields id, username, email, password, status
// During user registration, set the status to 'pending'
$status = 'pending';
// Insert user data into the database with status as 'pending'
// In the admin panel, fetch the pending registrations and approve them
// Connect to database and fetch pending users
$sql = "SELECT * FROM users WHERE status = 'pending'";
$result = mysqli_query($conn, $sql);
// Display pending users and provide option to approve
while($row = mysqli_fetch_assoc($result)) {
echo $row['username'] . " - " . $row['email'];
echo "<a href='approve_user.php?id=" . $row['id'] . "'>Approve</a><br>";
}
// In approve_user.php, update the status of the user to 'approved'
$id = $_GET['id'];
$sql = "UPDATE users SET status = 'approved' WHERE id = $id";
mysqli_query($conn, $sql);