How can PHP be used to prevent multiple registrations on a web portal?

To prevent multiple registrations on a web portal, we can implement a check in the registration process to verify if the email address or username being registered already exists in the database. If a match is found, we can display an error message prompting the user to try a different email or username.

// Check if email address already exists in the database
$email = $_POST['email'];
$query = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) > 0){
    echo "Email address already exists. Please use a different email.";
    exit();
}

// Check if username already exists in the database
$username = $_POST['username'];
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) > 0){
    echo "Username already exists. Please choose a different username.";
    exit();
}

// Proceed with registration if email and username are unique
// Add code here to insert user data into the database