How to create simple calculator in php

Simple calculator in php

Creating a simple calculator in php is as easy as drinking water now that you have decided to learn how to create a simple calculator in php “congratulation” you are in right place with the right tutorial with this tutorial you will learn how to create a calculator in php from starting to the end this is not only the tutorial about creating calculator in php you can find thousands of tutorial on internet which is about creating calculator but we have tried to create this tutorial in simple way that anyone can easily understand the concept and the way we are writing the code.

simple calculator in php

The code for creating simple calculator in php

<!DOCTYPE html>

<html>

<head>

<title> A simple calculator in php </title>

</head>

<body>

<form action=”calculator.php” method=”post”>

<table width=”500″ align=”center” bgcolor=”skyblue”>

<tr align=”center”>

<td colspan=”2″>

<h2>A simple php calculator</h2>

</td>

</tr>

<tr>

<td align=”right”>

<b>Enter Value 1:</b>

</td>

<td>

<input type=”text” name=”value1″ placeholder=”Enter Values Here!”/>

</td>

</tr>

<tr>

<td align=”right”>

<b>Enter Value 2:</b>

</td>

<td>

<input type=”text” name=”value2″ placeholder=”Enter Values Here!”/>

</td>

</tr>

<tr>

<td align=”right”>

<b>Select an Operator</b>

</td>

<td>

<select name=”opt”>

<option>Select Opertaor</option>

<option>+</option>

<option>-</option>

<option>/</option>

<option>*</option>

</select>

</td>

</tr>

<tr align=”center”>

<td colspan=”3″>

<input type=”submit” name=”calc” value=”Calculate Now!”/>

</td>

</tr>

</table>

</form>

<?php

if(isset($_POST[‘calc’]))

{

$value1 = $_POST[‘value1’];

$value2 = $_POST[‘value2’];

$opt = $_POST[‘opt’];

if($opt==’+’)

{

echo “<br><center>

<b style=’background: orange; padding: 10px;’>Your Answer is: “;

echo $value1+$value2;

echo “</b></center>”;

}

if($opt==’-‘)

{

echo “<br><center>

<b style=’background: orange; padding: 10px;’>Your Answer is: “;

echo $value1-$value2;

echo “</b></center>”;

}

if($opt==’/’)

{

echo “<br><center>

<b style=’background: skyblue; padding: 10px;’>Your Answer is: “;

echo $value1/$value2;

echo “</b></center>”;

}

if($opt==’*’)

{

echo “<br><center>

<b style=’background: pink; padding: 10px;’>Your Answer is: “;

echo $value1*$value2;

echo “</b></center>”;

}

}

?>

</body>

</html>

Watch the videos for better understanding of creating calculator in php


Watch the first video here after watching this video you can find the link for second video here

Click here to watch the second video

  • If you want to learn php and mysqli click on the image below to access the complete course

 

php and mysqli

Please follow and like us:
1

Leave a Reply

Your email address will not be published. Required fields are marked *