You are on page 1of 5

Group Members: Mushahid khan (215181)

Submitted To: Sir Haris

Subject: FSD Lab

Date: 14-feb-2024

HTML/CSS DESIGN:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
<link rel="stylesheet" href="styles.css">

<style>

body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.container {
width: 50%;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="radio"],
input[type="checkbox"],
input[type="submit"] {
margin-bottom: 10px;
}

label {
display: inline-block;
width: 100px;
}

</style>
</head>

<body>
<div class="container">
<h2>User Registration</h2>
<form action="database.php" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>

<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br>

<label>Gender:</label>
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female"
required>
<label for="female">Female</label><br>

<label>City:</label>
<input type="checkbox" id="city1" name="city[]" value="New York">
<label for="city1">New York</label>
<input type="checkbox" id="city2" name="city[]" value="London">
<label for="city2">London</label>
<input type="checkbox" id="city3" name="city[]" value="Tokyo">
<label for="city3">Tokyo</label><br>

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

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

Output:

DATABASE/PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "userdetails";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Escape user inputs for security


$email = $conn->real_escape_string($_POST['email']);
$age = $conn->real_escape_string($_POST['age']);
$gender = $conn->real_escape_string($_POST['gender']);
$cities = isset($_POST['city']) ? implode(", ", $_POST['city']) : '';
// Insert data into User table
$sql = "INSERT INTO user (email, age, gender, city) VALUES ('$email', '$age',
'$gender', '$cities')";

if ($conn->query($sql) === TRUE) {


echo "New record inserted successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close connection
$conn->close();
?>

You might also like