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

Web Development Using PHP (4341604) : Steps

The document outlines a practical exercise for creating a student registration form using PHP, demonstrating both POST and GET methods. It includes the code for two PHP files: index.php for the registration form and display.php for showing the submitted data. Users can input their name, email, gender, selected courses, and department, which are then displayed on the subsequent page.

Uploaded by

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

Web Development Using PHP (4341604) : Steps

The document outlines a practical exercise for creating a student registration form using PHP, demonstrating both POST and GET methods. It includes the code for two PHP files: index.php for the registration form and display.php for showing the submitted data. Users can input their name, email, gender, selected courses, and department, which are then displayed on the subsequent page.

Uploaded by

shubhamvj41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

WEB DEVELOPMENT USING PHP (4341604)

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.

1.​ POST Method

Steps:

1.​ index.php - Contains the registration form.


2.​ display.php - Displays the submitted data.

1. Create index.php (Student Registration Form)


<!DOCTYPE html>
<html>
<head>
<title>Student Registration Form</title>
</head>
<body>
<h2>Student Registration Form</h2>
<form action="display.php" method="post">
<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>

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


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

2. Create display.php (Show User Input)


<!DOCTYPE html>
<html>
<head>
<title>Student Details</title>
</head>
<body>
<h2>Student Registration Details</h2>

<?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>";
}

echo "<strong>Department:</strong> " . $_POST["department"] .


"<br>";
}
?>

<br><a href="index.php">Go Back</a>


</body>
</html>
OUTPUT:

2.​ POST Method

Steps:

1.​ index.php - Contains the registration form.


2.​ display.php - Displays the submitted data.

1. Create index.php (Student Registration Form)

<!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>

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


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

2. Create display.php (Show User Input)

<!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>";
}

echo "<strong>Department:</strong> " . $_GET["department"] .


"<br>";
}
?>

<br><a href="index.php">Go Back</a>


</body>
</html>

You might also like