We can make calculator in php using form:
Here is the code of making calculator.
In form action the file name that is calling when we put submit button. Here we calling the 'wel.php' file.
First file is saved any name but the second code is saved only in 'wel.php' file because we define here
<html>
<body>
<form action="wel.php" method="post">
<fieldset>
<font size="5" face="verdana" color="#7B68EE">
<b><em>Enter First Number: <input type="text" name="fnumber" ><br><br>
<b>Enter Second number: <input type="text" name="Snumber"><br><br>
Choose operation:
<input type="radio" name="operation" value="+" id="plus" checked="checked"><label for="plus">Add</label>
<input type="radio" name="operation" value="-" id="minus"><label for="minus">Subtract</label>
<input type="radio" name="operation" value="*" id="prod"><label for="prod">Multiply</label>
<input type="radio" name="operation" value="/" id="divide"><label for="divide">Divide</label>
<br><br>
<i> Get Result:</i> <input type="submit" value="Submit">
</font>
</fieldset>
</form>
</b></em>
</body>
</html>
This is wel.php file. It is called when we put submit button.
<html>
<body>
<?php
$fnum = $_POST["fnumber"];
$snum = $_POST["Snumber"];
$plus= $_POST["operation"];
$res='';
if($plus=="+")
{
$res= $fnum+$snum;
}
if($plus=="-")
{
$res= $fnum-$snum;
}
if($plus=="*")
{
$res= $fnum*$snum;
}
if($plus=="/")
{
$res= $fnum/$snum;
}
?>
<font color='#4B0082'><h1>Your Result Is</h1> <h2><?php echo $res;?></h2></font>
</body>
</html>
Here is the code of making calculator.
In form action the file name that is calling when we put submit button. Here we calling the 'wel.php' file.
First file is saved any name but the second code is saved only in 'wel.php' file because we define here
<html>
<body>
<form action="wel.php" method="post">
<fieldset>
<font size="5" face="verdana" color="#7B68EE">
<b><em>Enter First Number: <input type="text" name="fnumber" ><br><br>
<b>Enter Second number: <input type="text" name="Snumber"><br><br>
Choose operation:
<input type="radio" name="operation" value="+" id="plus" checked="checked"><label for="plus">Add</label>
<input type="radio" name="operation" value="-" id="minus"><label for="minus">Subtract</label>
<input type="radio" name="operation" value="*" id="prod"><label for="prod">Multiply</label>
<input type="radio" name="operation" value="/" id="divide"><label for="divide">Divide</label>
<br><br>
<i> Get Result:</i> <input type="submit" value="Submit">
</font>
</fieldset>
</form>
</b></em>
</body>
</html>
This is wel.php file. It is called when we put submit button.
<html>
<body>
<?php
$fnum = $_POST["fnumber"];
$snum = $_POST["Snumber"];
$plus= $_POST["operation"];
$res='';
if($plus=="+")
{
$res= $fnum+$snum;
}
if($plus=="-")
{
$res= $fnum-$snum;
}
if($plus=="*")
{
$res= $fnum*$snum;
}
if($plus=="/")
{
$res= $fnum/$snum;
}
?>
<font color='#4B0082'><h1>Your Result Is</h1> <h2><?php echo $res;?></h2></font>
</body>
</html>
0 comments:
Post a Comment