Jump to content
xisto Community
maddog39

Php Calculator Simple but cool.

Recommended Posts

Hello all,

 

I was eally bored the other day. So I decided to make a php calculator just out of the blue. I set it up and it works really good. You can see mine here. Ill give you guys the source code too if you want it. Here it is...

 

Name this calculate_forum.html

<html><head><title>Calculation Form</title></head><body><form method="post" action="calculate.php"><p>Value 1: <input type="text" name="val1" size="10"></p><p>Value 2: <input type="text" name="val2" size="10"></p><p>Calculation:<br><input type="radio" name="calc" value="add"> add<br><input type="radio" name="calc" value="subtract">  subtract<br><input type="radio" name="calc" value="multiply"> multiply<br><input type="radio" name="calc" value="divide"> divide</p><p><input type="submit" name="submit" value="Calculate"></p></body></html>
Name this calculate.php

<?phpif (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) {   header("Location: calculate_form.html");   exit;}if ($_POST[calc] == "add") {   $result = $_POST[val1] + $_POST[val2];} else if ($_POST[calc] == "subtract") {   $result = $_POST[val1] - $_POST[val2];} else if ($_POST[calc] == "multiply") {   $result = $_POST[val1] * $_POST[val2];} else if ($_POST[calc] == "divide") {   $result = $_POST[val1] / $_POST[val2];}echo "<title>Calculation Result</title>";echo "<p>The result of the calculation is: $result</p>";echo "<p><a href=\"calculate_form.html\" target=\"_self\">Do Another</a></p>";?>

Then upload the files to your server and go to http://www.yourdomain.com/calculate_form.html and enter 1 number in variable 1 and another number in variable 2. Then select a mathmatical method, then press calculate and then your answer will pop-up in a new page. The just click 'Do Another' to do another problem. Comments are appreciated. :D

Edited by maddog39 (see edit history)

Share this post


Link to post
Share on other sites

Hello all,

 

I was eally bored the other day. So I decided to make a php calculator just out of the blue. I set it up and it works really good. You can see mine here. Ill give you guys the source code too if you want it. Here it is...

 

Name this calculate_forum.html

<html><head><title>Calculation Form</title></head><body><form method="post" action="calculate.php"><p>Value 1: <input type="text" name="val1" size="10"></p><p>Value 2: <input type="text" name="val2" size="10"></p><p>Calculation:<br><input type="radio" name="calc" value="add"> add<br><input type="radio" name="calc" value="subtract">  subtract<br><input type="radio" name="calc" value="multiply"> multiply<br><input type="radio" name="calc" value="divide"> divide</p><p><input type="submit" name="submit" value="Calculate"></p></body></html>
Name this calculate.php

<?phpif (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) {   header("Location: calculate_form.html");   exit;}if ($_POST[calc] == "add") {   $result = $_POST[val1] + $_POST[val2];} else if ($_POST[calc] == "subtract") {   $result = $_POST[val1] - $_POST[val2];} else if ($_POST[calc] == "multiply") {   $result = $_POST[val1] * $_POST[val2];} else if ($_POST[calc] == "divide") {   $result = $_POST[val1] / $_POST[val2];}echo "<title>Calculation Result</title>";echo "<p>The result of the calculation is: $result</p>";echo "<p><a href=\"calculate_form.html\" target=\"_self\">Do Another</a></p>";?>
Then upload the files to your server and go to http://www.yourdomain.com/calculate_form.html and enter 1 number in variable 1 and another number in variable 2. Then select a mathmatical method, then press calculate and then your answer will pop-up in a new page. The just click 'Do Another' to do another problem. Comments are appreciated. :D

47123[/snapback]

I just tried it , it was fun. :D If I use it Ill make sure I provide a link back to your site. BTW nice layout! :D

Share this post


Link to post
Share on other sites

Wait till u see my layout =P. Nice php calculator....but there are others where u dont have seperates boxes for each value, i assuma u know php and u know how to use {echo} etc.

Share this post


Link to post
Share on other sites

It's good.but in my opinion,using php to make a calculator,is not quite efficient.PHP has to post/GET the data,then display the result,but JAVASCRIPT can display the result without POST/GET action.JAVASCRIPT is faster in doing these.

Share this post


Link to post
Share on other sites

Well I know it was a pointless project. But I did it out of bordum. I also dont have any knowledge of Javascript and right now im learning php. But I know that Javascript is better for this stuff. But it still works and I use it all the time. :D

Share this post


Link to post
Share on other sites

Nice, simple, useful program.

 

LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.

Share this post


Link to post
Share on other sites

LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.

 

Well, if you use JavaScript it will be fast. Really fast, because all the calculation happens server-side. With this calculator you don't have to use PHP, because you don't have to do anything that requires the server's capabilities.

 

Why have the visitor go to the page, fill out the form, send it to the server and then wait for the server to send a reply when you can have the visitor go to the page and fill out the form.

 

 

If you are learning PHP and want to do things like this, that's okay, but the better solution would be to use JavaScript (which isn't at all as complex as PHP is).

Share this post


Link to post
Share on other sites

Wow! you guys are really serious about your coding/scripts. Im scared, lol. I did this out of boardom. Thats why theres no copyright and other special stuff. :D:D:D

Share this post


Link to post
Share on other sites

Nice, simple, useful program.

 

LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.

48193[/snapback]


yes, php is much more simply, but javascript is faster. The javascript code are load in the HTML page, and when it's done, you click on the button 'Calculate' and the result come at the same time. PHP needs to load an other page, an go back to another calc, and load the page again....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.