You are on page 1of 3

Name: Syed Mohamid Raza Nadvi

Reg# Bcs221098
DB-Lab
Section-2
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fullName = $_POST['fullname'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmpassword'];

$errors = array();

// Validate required fields


if (empty($fullName)) {
$errors[] = "Full Name is required";
}

if (empty($email)) {
$errors[] = "Email Address is required";
}

if (empty($password)) {
$errors[] = "Password is required";
}

if (empty($confirmPassword)) {
$errors[] = "Confirm Password is required";
}

// Compare passwords
if ($password !== $confirmPassword) {
$errors[] = "Passwords do not match";
}

if (empty($errors)) {
// Registration successful
echo "Registration successful!";
} else {
// Display error messages
foreach ($errors as $error) {
echo $error . "<br>";
}
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h2>User Registration</h2>
<form method="post" action="">
<label for="fullname">Full Name:</label>
<input type="text" name="fullname" id="fullname" required><br>

<label for="email">Email Address:</label>


<input type="email" name="email" id="email" required><br>

<label for="password">Password:</label>
<input type="password" name="password" id="password" required><br>

<label for="confirmpassword">Confirm Password:</label>


<input type="password" name="confirmpassword" id="confirmpassword" required><br>

<input type="submit" value="Register">


</form>
</body>
</html>

Output

You might also like