How to Create a Simple Calculator in PHP – Video Tutorials

Like Tweet Pin it Share Share Email
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!

Comments (31)

  • 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

    • W/salam,
      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!

  • Nice work bro we love php. its incredible bro.

    Wali bro whats about online ustaad. any response from blogger officials.

    we were talking about your site. syed faizan Ali had told me thats wali bro have used some malicious code in hist site: read full comments here from top; what do you say.


    • Thanks for the comment, onlineustaad.com 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 onlineustaad.com, 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.

    • 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.

    • 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.

    • 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

    • 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.

    • Bro it is possible in threaded comment system you can check at. My blogger lab.com

      it has created this system.

  • Nice site Wali Bhai but there are some errors on your site you can improve your site click here to check errors http://www.woorank.com/en/review/bestbloggercafe.com

    • 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.

  • Great work Wali !! had a nice experience in phd that video is so useful us thanks for sharing online and offline research

  • 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:) http://www.mybloggerstricks.com

  • Assalam-o-Alikum, Brother recently i added two games on my wallpapers’s blog “sonic and “pacman” to get more traffic. so is this a right decision which i take?

    • W/salam,
      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.

  • Brother, Glad to know that Online Ustaad is coming back.

  • 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 !!!!!

    • 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

  • Its been awesome to know about how to do calculator progarm in php..Thanks for posting..
    best dissertation topics

  • Good information for me. please keep updating us with new posts. thank you so much .

  • i learn so many thingsfrom this blog.keep updating.thank you so much.

  • 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.

  • 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.

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

  • amazing this is very helpful for studentds


Speak Your Mind