How to Create a Simple Calculator in PHP – Video Tutorials

By | April 26, 2013
calculator in PHPI previously shared my complete PHP video series with you and now I’m going to share a simple online calculator with you which is created using PHP without MySQL. Because you can create any simple application in PHP by simply using IF statements. So I’ve done the same in this tutorial. However, My aim is to provide you a large number of tutorials in which we’ll be making small applications and projects such as online currency converter, visitors counter, love calculator, Luck Calculator and many more. I’ll be providing you video tutorials and the source code which we’d have used during the video tutorials. For now let’s create a simple calculator application in PHP. There will be 2 video tutorials which will practically teach you doing this and source code is also available for you to practice on.

Creating a simple calculator in PHP

Let’s assume, we want to create a simple calculator and without using MySQL. So yes, it is possible only by using IF statement in PHP. First you need to create a new file for writing the codes, and you can use Notepad or notepad++ for this purpose, though, I’ve used Notepad++ in these video tutorials. Just save the file and name it as calculator.php; save the file in the htdocs folder of your XAMPP Installation, because that is our root folder and we run files from that folder on our local server (Localhost). Now for creating a calculator you need to first create a form in HTML and add some input tags. Watch the video for creating it easily.
Here is the HTML code for the calculator, and we’ll later on add PHP code to this:

<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=’Calcaulate Now’>

And after creating the HTML form we need to start work in PHP so that this project will be completed, watch below video for practically learn about creating a PHP script for this calculator, and below the video I’ll provide the same source code as used in this tutorial:
Having watched above video tutorial, I hope you’ve understood creating it the PHP script easily for this simple calculator, however, the source code is being shared here, just copy it and paste it inside that file in which we already created an HTML form:

$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;

Now check your online calculator in your browser, and remember, always open your PHP files using this address: localhost. Sometimes mistakenly you directly click on the file which is inside a folder.
You may also love to read: Uploading Files via PHP
Our Calculator will be looking like this image: 

I hope you have enjoyed and learnt something new from this tutorial, I’m a development Geek and further interested to share more advance tutorials in PHP.

Comments and questions are warmly welcomed! Take Care Buddies!

Category: PHP Projects Video Tutorials Web Development

About Haiinteractive

Haiinteractive , for the past five years we have been in the IT industry with passion for web designing. We are passionate about bringing together our product engineering and management skills to create innovative solutions. Currently we are doing template selling, domain name selling. Our main focus is on providing high value services ranging from web designing, developing & maintaining, Web/Mobile Applications Development, Internet Marketing/SEO services and also other web-based industry specific products for businesses.Follow Us: Twitter : Facebook

31 thoughts on “How to Create a Simple Calculator in PHP – Video Tutorials

  1. Arslan Hussain

    Salam Wali bhai ye jo apki site ki top pay har waqt bar ati rehti hai wo kahan se ki hai apne plz bta den….. (Best blogger templete adsence high paying top adence alternative google seo book) ye wali black line

    1. Wali Khan

      Sorry to say brother, but comments will be answered here if they are in English and related to the post. Because this blog is totally in English language not in Urdu language.

      Thanks for understanding!

    1. Wali Khan

      Thanks for the comment, is currently under review of blogger support and the decision time is unknown.

      However, as Faizan said about the malicious code, that wasn’t actually a malicious code but was a live chat widget which I first checked on my blog as was explained by that site for blogger and after testing it on my blog, I shared a tutorial on that on my blog, I think after 10 hours the blog was marked as spam, however, if you use a malicious code in blogger widget area then the blog is deleted within seconds, therefore I understand it was not due to that script. Because that script didn’t have any malicious codes. I tested that again on my other blog. but nothing happened to other one.

    2. Hafeez Khan

      Wali Bro what is exact malicious code so that we never use its. because its danger for blogger.

      i have,nt more knowledge about its. what exact malicious code & which type of code or widget we should avoid in our blogger blog. So you mean that what am i saying.

      faizan has not give me a exact answer about this. So give me all tips about malicious code. i am coming back.

    3. Wali Khan

      Hafeez, malicious code is one sort of code in which the webmaster attempt to hack the website or temper with the system, and it is also called phishing, which is already stated in blogger spam policy. That kind of codes are very complex to read for the bots and they are not simply JavaScript, they may be however, but very randomly written and and difficult to understand for the bots.

    4. Hafeez Khan

      Thanks Wali Bro for kindly informations.

      Wali bro i have a question. Do you know any trick about how to place reply button with each replyer. like you are above me and i goes to my first comments at the top from which we beginging the discussion. so can we placed reply button with each child replyer commenter. to easy leave reply to that comments, not to go for the beginning. here is only reply button visible with only one commentators. we want to placed for all. How to do thats

    5. Wali Khan

      As far as I know, this is not yet possible in Blogger, because blogger threaded commenting system only supports one reply option. However, in WordPress blogs it is possible to have multiple replies to a single comment.

    1. Wali Khan

      Hmmm, these kind of errors occurs in all websites including big ones, they can never removed all at once. However, they may be reduced.

      And these kind of tools are also not 100% accurate.

    1. Wali Khan

      You are welcome Gopi, I hope you’ll learn and find more useful stuff on this blog regarding PHP and MYSQL in the future.

  2. khan bahi

    Wali khan your onlineustaad site wold best which mistakes to remove from Google now can explain and create the post him i am waiting for your post and that was next i am care on my blog or website. Hafeez khan now can discussed i will read it this mistakes appear him. inform me on post create any one announced them. your site has remove i am no happy then you long time a work and removed in seconds. Cheers:)

    1. Wali Khan

      When is restored successfully, I’ll surely write a complete post and guidance, so all of you can then take care.

    1. Wali Khan

      You better know brother what you are going to do, I don’t have any idea about games, because neither I play games nor read about them. So you better know than me.

    1. Wali Khan

      Yes bro, Onlineustaad will come back forever Inshallah with a new style and I’ll try to update it more frequently than old days. be in touch..

  3. multipleyourincome

    Bro what is the actual criteria for Ad-sense ????
    I have seen many blogs who have neither so much data nor any special template but Ad sense is working there.
    I have just seen a blog newly created in Support of Musharraf and it has less than 100 page views but Ad Sense is working there ???
    what is this mystery !!!!!

    1. Wali Khan

      Criteria for Adsense is very simple and clear, however, as you said there are many low quality blogs/sites where Adsense is running fine, but actually they may have account already, which they got on other blog/site and then they can insert Adsense ads on any site they own and is according to Adsense policies. However, the criteria for new Adsense accounts is something like this:
      A blog must have clean and user friendly design
      A blog must be 4 months old
      A blog must have original and unique content which gives value
      A blog must receive more than 50% targeted traffic from search engines
      A blog must adhere with Adsense program policies

  4. Brajesh Pandey

    wali sir i want to make your student if u dont mind because of i m working with PHP: so i hope u will help me in critical situation or any type of problem in php sir give me ur contact no.

  5. Muqaddas Shahzad

    Hello Dear..
    Can you help me to create a calculator on my website and for free?

    I want to show my calculator on this page (here I want to replace it with CPM banner at the right bottom side avaiable right above footer CPM banner):

    I want to make calculator with defined lists of values, like:
    1- # of Referrals (there should be a list of different referral quantities)
    2- Membership Level List (there should be a list of Memberships I am offering)
    3- # of Clicks (predefined list of possible clicks from 1-4)
    4- Period of Result (like: daily, weekly, monthly)

    Looking forward for your support.

  6. sashwat kumar

    How to create a website with admin panel…. And how to generate html code


Speak Your Mind