0% found this document useful (0 votes)
72 views4 pages

LAB 10: Form Handling in PHP: Exercises

This document contains instructions and code examples for 3 exercises on form handling in PHP from a Web Systems and Technologies lab. The first exercise demonstrates accepting user input via an HTML form and validating the data with PHP. The second defines a circle class and cylinder subclass to calculate volume. The third sets up a login session using PHP sessions on successful form submission.

Uploaded by

Hasan
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)
72 views4 pages

LAB 10: Form Handling in PHP: Exercises

This document contains instructions and code examples for 3 exercises on form handling in PHP from a Web Systems and Technologies lab. The first exercise demonstrates accepting user input via an HTML form and validating the data with PHP. The second defines a circle class and cylinder subclass to calculate volume. The third sets up a login session using PHP sessions on successful form submission.

Uploaded by

Hasan
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/ 4

ITL-226: Web System and Technologies Lab

Khizar Hussain Siddiqui (02-235201-036)


Muhammad Ehsan Ali
Semester BS IT - 05
02-235201-030

LAB 10: Form Handling in PHP

Exercises

Exercise 1
Using html form accept the user details like name, city, pincode, and email which are processed by php program for the
constraint you have defined for each data. Produce the report for violation. For example, name is compulsory field, pincode
is 6 digits, etc.
<?php
echo "Your name is ".$_POST['name']."<br>";
echo "Your city is ".$_POST['city']."<br>";
echo "Your email is".$_POST['email']."<br>";
 if(strlen($_POST['pincode'])<6)
echo "Your pin must have 6 digits"."<br>";
else
echo "Your Pincode is :".$_POST['pincode']."<br>";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Task 1 </title>
</head>
<body>
<form action="task1.php" method="post" >
<table>
<tr><td> Name: <input type="text" name="name" placeholder="Enter your name" required/></td>
</tr>
<tr><td> City: <input type="text" name="city" placeholder="Enter your city" required/> </td>
</tr>
<tr><td> Email: <input type="text" name="email" placeholder="Enter your email" required/>
</td></tr>
<tr><td> Pincode: <input type="text" name="pincode" placeholder="Enter your pincode" required/>
</td>
</tr>
<tr><td><input type="submit" value="Submit" /></td></tr>
</table>
</form>
</body>
Department of Computer Sciences Semester BS IT 5
ITL-226: Web Systems and Technologies Lab Lab 10: Form-Handling PHP
</html>
ITL-226: Web System and Technologies Lab
Khizar Hussain Siddiqui (02-235201-036)
Semester BS IT - 05

Exercise 2

Write PHP program that defines circle as object and inherit cylinder from it. Compute the volume of the cylinder.
<html>
<body>
<?php
class circle
{
private $length;
private $breath ;
function _construct()
{
$this->length = 0;
$this->breath = 0;
}
function set_data($x,$y)
{
$this->length = $x;
$this -> breath = $y;
}
function print_data()
{
print("length =:" . $this ->length . "<br>");
print("breath=:" . $this ->breath . "<br/>");
}
function volume()
{
return $this->length* $this->breath;
}
function _destruct()
{
Print("object destroyed");
}
}
$r = new circle();
//object created
$r->set_data(5,10);
//initialize
$r->print_data();
print("Area is :" . $r->volume());
unset($sr);
?>
</body>
Department of Computer Sciences Semester BS IT 5
ITL-226: Web Systems and Technologies Lab Lab 10: Form-Handling PHP
</html>
ITL-226: Web System and Technologies Lab
Khizar Hussain Siddiqui (02-235201-036)
Semester BS IT - 05

Exercise 3

Write a program to set session on successful login.


<?php
$name = $_POST['uid'];
$pass = $_POST['pwd'];
session_start();
$_SESSION['userid'] = $name;
$_SESSION['password'] = $pass;
$SID = session_id();
print("thank you ". $name. " you are logged in <br/>");
print("click <a href = 'task3(2).php?PHPSESSID = ".$SID."'>login</a> to go to next page ");
?>

<html>
 <body>
 <form action = "task3.php" method = "post">
userid : <input type = "text" name = "uid"/><br/><br/>
password : <input type = "password" name= "pwd"/><br/></br>
<input type= "submit" value = "login"/>
 </form>
 </body>
</html>

<?php
session_start();
if(!isset($_SESSION['userid'])){
print("you are not logged in");
print("<a href =\task3.html\”>goto</a> login page");

}else{
print("you are logged in, your session data is:<br/><br/>");
print("userid =" . $_SESSION['userid']."<br/></br>");
print("password =" . $_SESSION['password']."<br/></br>");
print("you can proceed further");
 }
 ?>

Department of Computer Sciences Semester BS IT 5


ITL-226: Web Systems and Technologies Lab Lab 10: Form-Handling PHP
ITL-226: Web System and Technologies Lab
Khizar Hussain Siddiqui (02-235201-036)
Semester BS IT - 05

Department of Computer Sciences Semester BS IT 5


ITL-226: Web Systems and Technologies Lab Lab 10: Form-Handling PHP

You might also like