Web Development Using PHP (4341604) : Steps
Web Development Using PHP (4341604) : Steps
PRACTICAL 7:
Exercise. Create a student registration form using text box, check box, radio button,
select,submit button. And display user inserted value in new PHP page using GET and
POST Method.
Steps:
<label for="email">Email:</label>
<input type="email" name="email" required><br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female <br><br>
<label>Courses:</label>
<input type="checkbox" name="courses[]" value="Python"> Python
<input type="checkbox" name="courses[]" value="Java"> Java
<input type="checkbox" name="courses[]" value="C++"> C++ <br><br>
<label for="department">Department:</label>
<select name="department">
<option value="Computer Science">Computer Science</option>
<option value="Information Technology">Information
Technology</option>
<option value="Electronics">Electronics</option>
</select><br><br>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<strong>Name:</strong> " . $_POST["name"] . "<br>";
echo "<strong>Email:</strong> " . $_POST["email"] . "<br>";
echo "<strong>Gender:</strong> " . $_POST["gender"] . "<br>";
if (!empty($_POST["courses"])) {
echo "<strong>Courses:</strong> " . implode(", ",
$_POST["courses"]) . "<br>";
} else {
echo "<strong>Courses:</strong> None selected<br>";
}
Steps:
<!DOCTYPE html>
<html>
<head>
<title>Student Registration Form</title>
</head>
<body>
<h2>Student Registration Form</h2>
<form action="display.php" method="get">
<label for="name">Name:</label>
<input type="text" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" name="email" required><br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="Male"> Male
<input type="radio" name="gender" value="Female"> Female
<br><br>
<label>Courses:</label>
<input type="checkbox" name="courses[]" value="Python">
Python
<input type="checkbox" name="courses[]" value="Java"> Java
<input type="checkbox" name="courses[]" value="C++"> C++
<br><br>
<label for="department">Department:</label>
<select name="department">
<option value="Computer Science">Computer
Science</option>
<option value="Information Technology">Information
Technology</option>
<option value="Electronics">Electronics</option>
</select><br><br>
<!DOCTYPE html>
<html>
<head>
<title>Student Details</title>
</head>
<body>
<h2>Student Registration Details</h2>
<?php
if ($_SERVER["REQUEST_METHOD"] == "GET") {
echo "<strong>Name:</strong> " . $_GET["name"] . "<br>";
echo "<strong>Email:</strong> " . $_GET["email"] . "<br>";
echo "<strong>Gender:</strong> " . $_GET["gender"] . "<br>";
if (!empty($_GET["courses"])) {
echo "<strong>Courses:</strong> " . implode(", ",
$_GET["courses"]) . "<br>";
} else {
echo "<strong>Courses:</strong> None selected<br>";
}