0% found this document useful (0 votes)
37 views5 pages

Lab 02 FSD

The document describes an HTML/CSS form for user registration that collects a user's email, age, gender, and city. It includes input fields like text, radio buttons, and checkboxes. The form action links to a PHP file that connects to a database and inserts the user's submitted data into a user table. The PHP file escapes the input values for security before executing an SQL query to insert a new record.

Uploaded by

Mushahid khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Lab 02 FSD

The document describes an HTML/CSS form for user registration that collects a user's email, age, gender, and city. It includes input fields like text, radio buttons, and checkboxes. The form action links to a PHP file that connects to a database and inserts the user's submitted data into a user table. The PHP file escapes the input values for security before executing an SQL query to insert a new record.

Uploaded by

Mushahid khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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