0% found this document useful (0 votes)
2 views

Write a PHP program to demonstrate Form Elements (input elements)

The document outlines an experiment to create a PHP program that demonstrates form elements, including input fields for name, roll number, and department. It details the required facilities, procedure for coding and running the program using XAMPP, and provides a sample PHP code for the form. The objective is to showcase how to input and display data using HTML forms in PHP.

Uploaded by

HOD-DIT PSG-PTC
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Write a PHP program to demonstrate Form Elements (input elements)

The document outlines an experiment to create a PHP program that demonstrates form elements, including input fields for name, roll number, and department. It details the required facilities, procedure for coding and running the program using XAMPP, and provides a sample PHP code for the form. The objective is to showcase how to input and display data using HTML forms in PHP.

Uploaded by

HOD-DIT PSG-PTC
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NUMBER 07.

A
DATE DAY MONT YEAR PHP PROGRAM TO DEMONSTRATE FORM
H ELEMENTS

OBJECTIVE (AIM) OF THE EXPERIMENT


To write a PHP program to demonstrate Form Elements (input elements).
FACILITIESREQUIRED

S.NO FACILITIES REQUIRED QUANTITY


1 System 1
2 O/S Windows / Linux OS
3 S/W name Any Browser
4 XAMPP server Any version
WEBLAYOUT
NAME
ROLL.NO
DEPT
BUTTON 1 BUTTON 2
PROCEDURE
 Write code in Notepad.
 Save the file with any name followed by filename .php extension.
 Connect to XAMPP server.

 Save the file in the XAMPP location.


 In XAMPP location you should save it in htdocs.
 Go to any browser and type localhost:8080/filename.php.

 Input the details and record the output.


PROGRAM
ex7a.php
<html>
<head>
<title>HTML Forms Input and Display in PHP</title>
</head>
<body>
<style
type="text/css">
body {
font-family:
arial; size:
12px;
};
</style>
<?php
$display="";
$name = isset($_POST['name']) ? $_POST['name'] : '';
$rollno = isset($_POST['rollno']) ? $_POST['rollno'] : '';
$dept = isset($_POST['dept']) ? $_POST['dept'] : '';
if(isset($_POST['submit']))
{
$display .= "<h2> Display Results </h2>";
$display .= "Name : " .
($name) ."<br/>";

$display .= "Roll No:


".
($rollno)."<br/>";
$display .= "Dept: " .
($dept)."<br />";
}
if (isset($_POST['clear'])) {
$name ="";
$rollno ="";
$dept ="";
$display ="";
}
?>
<h2> HTML Forms Input and Display in PHP </h2>
<form method="post">
<p>Name: <input
type="text"
name="name"
value="<?php echo
$name; ?>"></p>
<p>Roll No: <input
type="text"
name="rollno" value="<?
php echo $rollno;
?>"></p>
<p>Dept: <input
type="text"
name="dept"
value="<?php echo
$dept; ?>"></p>
<input type="submit" name="submit" value="Submit" />
<input type="submit" name="clear" value="Clear" />
</form>
<?php
echo $display;
?>
</body>
</html>
OUTPUT:

RESULT: Thus we have created a PHP program to demonstrate Form Elements (input elements).

You might also like