PB1
PB1
PHP program to implement student registration form using Labels, Text Boxes, Text
Area, Checkbox, Radio Buttons, Select and Submit button. (First Name, Last Name,
Address, E-Mail, Mobile, City, State, Gender, Hobbies, Blood Group). Display user
inserted value in a new PHP page in a neat format.
PB1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
<style>
table {
border-collapse: collapse;
width: 50%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>
<h2>Student Registration Form</h2>
<form action="PB1.php" method="post">
<table>
<tr>
<td><label for="firstName">First Name:</label></td>
<td><input type="text" id="firstName" name="firstName" required></td>
</tr>
<tr>
<td><label for="lastName">Last Name:</label></td>
<td><input type="text" id="lastName" name="lastName" required></td>
</tr>
<tr>
<td><label for="address">Address:</label></td>
<td><textarea id="address" name="address" required></textarea></td>
</tr>
<tr>
<td><label for="email">E-Mail:</label></td>
<td><input type="email" id="email" name="email" required></td>
</tr>
<tr>
<td><label for="mobile">Mobile:</label></td>
<td><input type="text" id="mobile" name="mobile" required></td>
</tr>
<tr>
20
<td><label for="city">City:</label></td>
<td><input type="text" id="city" name="city" required></td>
</tr>
<tr>
<td><label for="state">State:</label></td>
<td><input type="text" id="state" name="state" required></td>
</tr>
<tr>
<td><label for="gender">Gender:</label></td>
<td>
<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>
</td>
</tr>
<tr>
<td><label for="hobbies">Hobbies:</label></td>
<td>
<input type="checkbox" id="hobby1" name="hobbies[]" value="Reading">
<label for="hobby1">Reading</label>
<input type="checkbox" id="hobby2" name="hobbies[]" value="Sports">
<label for="hobby2">Sports</label>
<input type="checkbox" id="hobby3" name="hobbies[]" value="Music">
<label for="hobby3">Music</label>
</td>
</tr>
<tr>
<td><label for="bloodGroup">Blood Group:</label></td>
<td>
<select id="bloodGroup" name="bloodGroup" required>
<option value="">Select</option>
<option value="A+">A+</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B-">B-</option>
<option value="AB+">AB+</option>
<option value="AB-">AB-</option>
<option value="O+">O+</option>
<option value="O-">O-</option>
</select>
</td>
</tr>
</table>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
21
PB1.PHP
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Information</title>
</head>
<body>
<h2>Student Information</h2>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<p><strong>First Name:</strong> " . $_POST["firstName"] . "</p>";
echo "<p><strong>Last Name:</strong> " . $_POST["lastName"] . "</p>";
echo "<p><strong>Address:</strong> " . $_POST["address"] . "</p>";
echo "<p><strong>E-Mail:</strong> " . $_POST["email"] . "</p>";
echo "<p><strong>Mobile:</strong> " . $_POST["mobile"] . "</p>";
echo "<p><strong>City:</strong> " . $_POST["city"] . "</p>";
echo "<p><strong>State:</strong> " . $_POST["state"] . "</p>";
echo "<p><strong>Gender:</strong> " . $_POST["gender"] . "</p>";
if (!empty($_POST["hobbies"])) {
echo "<p><strong>Hobbies:</strong> " . implode(", ", $_POST["hobbies"]) . "</p>";
}
echo "<p><strong>Blood Group:</strong> " . $_POST["bloodGroup"] . "</p>";
}
?>
</body>
</html>
OUTPUT:
22