This tutorial will teach you how to make a calculator using PHP.
Firstly, create a new .php document and copy/paste the following code into it.
| <?php /* Calculator */ if($submit) { if($operator == '*') { echo $numa * $numb; } elseif($operator == '/') { echo $numa / $numb; } elseif($operator == '+') { echo $numa + $numb; } elseif($operator == '-') { echo $numa - $numb; } } else { ?> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" name="numa" size="10"> <input type="text" name="operator" size="2"> <input type="text" name="numb" size="10"> <input type="submit" value="Calculate" name="submit"> </form> <?php } ?> |
Legend:
* Multiply
- Subtract
/ Divide
+ Add
Related Articles
- Understanding HTML Color Codes, Explained in Plain EnglishWhen I help people with web pages, I always encourage them to edit the HTML directly and not rely on programs like Microsoft FrontPage or Adobe GoLive to layout their pages. One of the first things that people have a hard time grasping is what
- Intro To Object: Creating Your First ClassYou have havent done so yet, I strongly recommend you first read my Intro To Object before starting this tutorial.
- 5 Unique Ways to get more Free TrafficOk so the first way to get traffic is not particularly unique. But the fact is that you will get lots of traffic by writing articles. The traffic wont come immediately but it will come. Articles will also bring link popularity...
- An Easy Way to Choose Attractive Color CombinationsLots of people struggle to come up with attractive color combinations when designing logos, banners or web sites. So, heres an easy technique that only takes a few minutes...
- Hexadecimal Color Notation On The WebWhen designing elements for your webpage, you will often be called upon to specify a color. For example, the code for a span shown below specifies that the color of the text within the span will be yellow.
- Increase Website Traffic By Giving Them What They WantWant to increase your traffic? Ask yourself why most successful shops routinely rearrange their product displays. Keep it fresh and give the customer what he wants.
- Traffic, Visitor, And Customer Analysis - Two MetricsIve developed two metrics I think are among the most important you can track, no matter what kind of site you have or what the objective of the site is. They are designed to focus in right on the biggest problem most sites have - getting visitors to go past the first page they see on your site.....
- Beginners Guide to PPC Search Engines (Part 1)This article is a complete survey of the basics of PPC Search Engines. The author explains each term so that a beginner can understand and benefit from the points presented here.
- Website Creation in Russian Segment of the Internet (Exclusive Article)How to create and promote your website in runet? How to make the website profitable and competitive? This article will clear the situation up for you. Well study some points of promotion and web design in runet.
- Generate HTML Files With PHP To Reduce The Server LoadPIM Team Case Study How you can have a site with tons of visitors without to crash the server? Problem PIM Team Bulgaria had the task to create a quiz site able to hold an extreme server load. The site is currently installed as beta version at www.quizzy.net. Goals - Create a ...
