Sujal Moradiya-21id01it021

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Sujal Moradiya

21ID01IT021

Practical 5

1. Create an interface using HTML and Php to accept user


input using _GET and _POST method and display the
result on a new page.
<!DOCTYPE html>
<html>
<head>
<title> <h1> practical 5 </h1> </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method='POST'>
<h2>Please input your name:</h2>
<input type="text" name="name">
<input type="submit" value="Submit Name">
</form>
<?php
//Retrieve name from query string and store to a local variable
$name = $_POST["name"];
echo "<h3>". "Hello". " $name"." </h3>";
?>
</body>
</html>
2. Create an interface using HTML and PHP to find the
factorial of a number and display the result on the
same page.
<html>
<head>
<title>Practical 5</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST){
$fact = 1;

$number = $_POST['number'];
echo "Factorial of $number:<br><br>";

for ($i = 1; $i <= $number; $i++){


$fact = $fact * $i;
}
echo $fact . "<br>";
}
?>
</body>
</html>
3. Create a script to find the greatest among
five numbers.
Page 1

<html>
<head>
<title>Practical 5</title>
</head>
<body>
<form method="post" action="cmp.php">
Enter the first number:<br>
<input type="text" name="num1"><br>
Enter the second number:<br>
<input type="text" name="num2"><br>
Enter the third number:<br>
<input type="text" name="num3"><br>
Enter the fourth number:<br>
<input type="text" name="num4"><br>
Enter the fifth number:<br>
<input type="text" name="num5">
<br>
<input type="submit" name="submit">
</form>
</body>
</html>

Page 2

<?php
if(isset($_POST["submit"]))
{
$num1=$_POST["num1"];
$num2=$_POST["num2"];
$num3=$_POST["num3"];
$num4=$_POST["num4"];
$num5=$_POST["num5"];
if($num1>$num2 && $num1>$num3 && $num1>$num4 && $num1>$num5)
{
echo $num1;
}
else
{
if($num2>$num1 && $num2>$num3 && $num2>$num4 && $num2>$num5)
{
echo $num2;
}
else
{
if($num3>$num1 && $num3>$num2 && $num3>$num4 && $num3>$num5)
{
echo $num3;
}
else
{
if($num4>$num1 && $num4>$num2 && $num4>$num3 && $num4>$num5)
{
echo $num4;
}
else
{
if($num5>$num1 && $num5>$num2 && $num5>$num3 && $num5>$num4)
{
echo $num5;
}
}

}
}
}
}
?>
4.Create an interface to input the result details of
the student and print the entries on the next page
in the form of a table. Entries should be:
a. Name
b. Enrolment Number
c. Marks of Five Subjects
d. Grade calculation using script
e. Total Marks calculation using script

<html>
<body bgcolor="#959595">
<table border="5px">
<tr>
<td>
Name :
</td>
<td>
<?php
echo $_POST["name"];
?>
</td>
</tr>
<tr>
<td>
Enrollment no :
</td>
<td>
<?php
echo $_POST["en"];
?>
</td>
</tr>
<tr>
<td>
Web Tech :
</td>
<td>
<?php
echo $_POST["s1"];
?>
</td>
</tr>
<tr>
<td>
Java :
</td>
<td>
<?php
echo $_POST["s2"];
?>
</td>
</tr>
<tr>
<td>
Application development :
</td>
<td>
<?php
echo $_POST["s3"];
?>
</td>
</tr>
<tr>
<td>
C:
</td>
<td>
<?php
echo $_POST["s4"];
?>
</td>
</tr>
<tr>
<td>
Python :
</td>
<td>
<?php
echo $_POST["s5"];
?>
</td>
</tr>
<tr>
<td>
Total marks obtain :
</td>
<td>
<?php
$marks =
$_POST["s1"]+$_POST["s2"]+$_POST["s3"]+$_POST["s4"]+$_POST["s5"];
echo $marks;
?>
</td>
</tr>
<tr>
<td>
Percentage :
</td>
<td>
<?php
$percent = $marks* 100 /$_POST["to"];
echo $percent." %";
?>
</td>
</tr>
<tr>
<td>
Grade :
</td>
<td>
<?php
if ($percent>=90)
{ echo "A+ Pass";
}
elseif ($percent>=80 && $percent<=90)
{ echo "A Pass";
}
elseif ($percent>=70 && $percent<=80)
{ echo "B+ Pass";
}
elseif ($percent>=60 && $percent<=70)
{ echo "B Pass";
}
elseif ($percent>=50 && $percent<=60)
{ echo "C Pass";
}
elseif ($percent>=40 && $percent<=50) {
echo "D Pass"; } elseif ($percent>=36
&& $percent<=40)
{ echo "E Pass";
}
elseif ($percent>=0 && $percent<=36)
{ echo "F Fail"; }
else {
echo "Invalid answer";
}
?>
</td>
</tr>
</table>
</body>
</html>

You might also like