|
|
|
|
![]() ![]() |
Feb 6 2005, 03:13 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
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 CODE <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 CODE <?php if (($_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 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. This post has been edited by maddog39: Feb 6 2005, 03:14 AM |
|
|
|
Feb 6 2005, 04:26 AM
Post
#2
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 130 Joined: 3-February 05 From: Toronto, Canada Member No.: 3,569 |
QUOTE(maddog39 @ Feb 6 2005, 03:13 AM) 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 CODE <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 CODE <?php if (($_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 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. I just tried it , it was fun. |
|
|
|
Feb 6 2005, 04:54 AM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 24 Joined: 5-February 05 From: Middle of Now-where Member No.: 3,619 |
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. |
|
|
|
Feb 6 2005, 02:12 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
Lol, thanks guys.
|
|
|
|
Feb 7 2005, 04:35 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 204 Joined: 6-October 04 From: London, uk Member No.: 1,444 |
cool but a bit pointless
|
|
|
|
Feb 8 2005, 10:05 AM
Post
#6
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 136 Joined: 20-October 04 From: Thailand Member No.: 1,840 |
Good work, guy.
That's a good once. |
|
|
|
Feb 8 2005, 11:07 AM
Post
#7
|
|
|
.: http://www.xgnews.tk :. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 119 Joined: 29-October 04 Member No.: 2,025 |
Heh, nice one
It's a very simple, yet usefull program |
|
|
|
Feb 8 2005, 12:37 PM
Post
#8
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 114 Joined: 9-August 04 From: Suzhou Jiangsu China Member No.: 743 |
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. |
|
|
|
Feb 8 2005, 05:15 PM
Post
#9
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 208 Joined: 27-January 05 From: LI, New York Member No.: 3,448 |
Well I know it was a pointless project. But I did it out of bordum. I also dont have any kno |