Calculator Assignment
Calculator Assignment
Batch : 13
Assignment :1
// Add.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
</head>
<style>
</style>
<body>
<table border="1">
<tr>
<td><label >First value</label> <td><input type="text"
name="val1"></td> </td>
</tr>
<tr>
<td><label >Second value</label> <td><input type="text"
name="val2"></td> </td>
</tr>
<tr>
<td><button type="submit" name="addbt">ADD</button><td><button
type="submit" name="subbt">SUB</button></td>
</tr>
<tr>
<td><button type="submit" name="mulbt">MUL</button></td>
<td><button type="submit" name="divbt">DIV</button></td>
</tr>
</table>
</form>
</body>
</html>
//Add.html ends here
<?php
if(isset($_POST['val1']) && isset($_POST['val2'])) {
$var1 =$_POST['val1'];
$var2 = $_POST['val2'];
if( isset($_POST['addbt'])){
$add=$var1+ $var2;
echo " <h2>Sum of two values is = $add </h2> ";
}
else if(isset($_POST['subbt'])){
$sub=$var1- $var2;
echo " <h2>Subtraction of two values is = $sub </h2> ";
}
else if(isset($_POST['mulbt'])){
$mul=$var1 * $var2;
echo " <h2>Multiplication of two values is = $mul</h2> ";
}
else if(isset($_POST['divbt'])){
if($var2==0){
echo "Division not possible";
}
else {
$div=$var1 / $var2;
echo " <h2>Division of two values is = $div</h2> ";
}
}
else{
echo "Invalid values ";
}
}
?>
//Add.php ends here