Create a simple Online Calculator in PHP

Hey folks!

Today’s tutorial in PHP is gonna be about creating a very simple calculator using Arithmetic operators in PHP. This is something you can easily do by practicing basic arithmetic operations in PHP, there is no need to use MySQL or any database for this project. PHP is a very easy to use programming language where you can learn to develop small web applications. And, I’m teaching you the same here on this blog. Let’s create a very basic calculator in PHP with video tutorials to watch and learn from.

calculator in PHP
Note: This is just an example image, the calculator in the tutorial is very basic one!

For creating a simple calculator or currency converter, you don’t need to store anything inside a database, because there are arithmetic operators available in PHP by default i.e +,-,*, / etc. So you can use these operators to calculate the values in the browser without going to the database. Now let’s begin.

How to create a calculator using PHP?

  • Open notepad and create a new file called “calculator.php”
  • Save it and give the name & extension as mentioned above
  • Now paste below code into that file you just created
<title>Simple PHP Calculator</title>
<form method=’post’ action=’calculator.php’>
<input type=’text’ name=’value1′>
<input type=’text’ name=’value2′><select name=’action’>
<input type=’submit’ name=’submit’ value=’Calculate Now’></form>
if(isset($_POST[‘submit’])){$value1 = $_POST[‘value1’];
$value2 = $_POST[‘value2’];
$action = $_POST[‘action’];

echo “<b>Your Answer is:</b><br>”;
echo $value1+$value2;

echo “<b>Your Answer is:</b><br>”;
echo $value1-$value2;

echo “<b>Your Answer is:</b><br>”;
echo $value1*$value2;

echo “<b>Your Answer is:</b><br>”;
echo $value1/$value2;


The above simple piece of HTML & PHP code will display a simple calculator in the browser, where you’ll have to put some values and select an option to do the action, and you’ll click “Calculate” to find the result.

Now if you want to learn this thing from scratch, then kindly watch below videos:

Creating a Calculator in PHP video #1

Creating a Calculator in PHP video #2

After watching the video tutorials, I can assume you’ve easily got what you were looking for. In my coming video tutorials, We’ll use an online currency converter and will use the same syntax similar to this one.

Before you close this page, have a look at following PHP tutorials: 

So if you have got any questions, then kindly let me know by commenting below the post. We always try to help you out in web development, because we know by adding values to your opinions, we’ll also get some great suggestions from you in the future. So let’s make the web a better place for both you and us. Happy Web Development!

About Abdul Wali

Abdul Wali is a professional blogger, marketer and web developer working online for last 5 years, he's been deeply involved in PHP, Web Development, SEO and computer video tutorials in different languages i.e English, Urdu and Pashto. You can catch him on and add him on Facebook.

Check Also


Best Websites to Buy PHP Scripts & Themes

PHP is a powerful web development language and many popular platforms are built with PHP ...

  • vietthu

    it show error that “Parse error: parse error in C:\xampp\htdocs\tut\calculator.php on line 28”,please fix it.tks

  • Anas Ishtiaq

    i thing in coding instead of ‘ this sign ” this sign must be used.