PHP script to demonstrate the use of switch case

Enter Number and select the switch case using form

(decision.html)

<html>
<head>
<style>
h1{color:white;font-family:comic sans ms;}h2{color:white;font-family:comic sans ms;}
</style>
</head>
<body bgcolor="orange">
<h1>Calculator</h1>
<h2> Insert 1 for addition</h2>
<h2> Insert 2 for subtraction</h2>
<h2> Insert 3 for multiplication</h2>
<h2> Insert 4 for division</h2>
<h2> Insert 5 for remainder</h2>
<form method="POST" action="decision.php">
<h1>Number1:<input type="number" name="n1"><br>
<h1>Number2:<input type="number" name="n2"><br>
Operation:<input type="number" placeholder="Operation" name="n3"><br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>






Embed Php File into the form tag

(decision.php)

<?php
$a=$_POST["n1"];
$b=$_POST["n2"];
$c=$_POST["n3"];
switch($c)
{
case 1:
$add=$a+$b;
echo $add;
break;
case 2:
$sub=$a-$b;
echo $sub;
break;
case 3:
$mul=$a*$b;
echo $mul;
case 4:
$div=$a/$b;
echo $div;
case 5:
$rem=$a%$b;
echo $rem;
}
?>



























Comments