maddog39 0 Report post Posted February 6, 2005 (edited) 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. Edited February 6, 2005 by maddog39 (see edit history) Share this post Link to post Share on other sites
Cammy 0 Report post Posted February 6, 2005 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. 47123[/snapback] I just tried it , it was fun. If I use it Ill make sure I provide a link back to your site. BTW nice layout! Share this post Link to post Share on other sites
AnimeExile 0 Report post Posted February 6, 2005 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
maddog39 0 Report post Posted February 6, 2005 Lol, thanks guys. Share this post Link to post Share on other sites
krap 0 Report post Posted February 7, 2005 cool but a bit pointless Share this post Link to post Share on other sites
nancmu 0 Report post Posted February 8, 2005 Good work, guy. That's a good once. Share this post Link to post Share on other sites
Deaths Aprentice 0 Report post Posted February 8, 2005 Heh, nice one .It's a very simple, yet usefull program Share this post Link to post Share on other sites
LuciferStar 0 Report post Posted February 8, 2005 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
maddog39 0 Report post Posted February 8, 2005 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. Share this post Link to post Share on other sites
Xedos 0 Report post Posted February 8, 2005 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
bjrn 0 Report post Posted February 8, 2005 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
Deaths Aprentice 0 Report post Posted February 8, 2005 PHP is indeed harder to learn.The basics are easy though, but it gets harder once you want better programs.But, once you know PHP, it's the best scripting language, if you ask me.(Partly because it doesn't take up that much resources ) Share this post Link to post Share on other sites
LuciferStar 0 Report post Posted February 9, 2005 LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn. 48193[/snapback] YES!but not to do such a thing. Share this post Link to post Share on other sites
maddog39 0 Report post Posted February 10, 2005 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. Share this post Link to post Share on other sites
FaLgoR 0 Report post Posted February 11, 2005 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