You are on page 1of 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