Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Php Calculator


21 replies to this topic

#1 maddog39

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 208 posts
  • Location:LI, New York
  • Interests:Web programming, computer programming, computer games, and Play Station2. :D

Posted 06 February 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
<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
<?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. :D

Edited by maddog39, 06 February 2005 - 03:14 AM.


#2 Cammy

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 130 posts
  • Location:Toronto, Canada
  • Interests:Blogs, Reading, Forums, Graphics, Poetry, Working Out, Health, Family, Beauty, Paint Shop Pro, Arts, Festivals, Music( Soul, R&amp;B, Hip Hop, Rap, Reggae, Soca, World, Rock, Alternative, Pop) lots more...

Posted 06 February 2005 - 04:26 AM

maddog39, on Feb 6 2005, 03:13 AM, said:

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
<?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. :D

View Post



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


#3 AnimeExile

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 24 posts
  • Location:Middle of Now-where
  • Interests:ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,ANime,and gaming =P

Posted 06 February 2005 - 04:54 AM

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.

#4 maddog39

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 208 posts
  • Location:LI, New York
  • Interests:Web programming, computer programming, computer games, and Play Station2. :D

Posted 06 February 2005 - 02:12 PM

Lol, thanks guys. :D

#5 krap

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 204 posts
  • Gender:Male
  • Location:London, uk
  • Interests:php, wml, html , computers etc

Posted 07 February 2005 - 04:35 PM

cool but a bit pointless :D :D

#6 nancmu

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 136 posts
  • Location:Thailand
  • Interests:Computer.....

Posted 08 February 2005 - 10:05 AM

Good work, guy. :D
That's a good once. :D

#7 Deaths Aprentice

    .: http://www.xgnews.tk :.

  • Kontributors
  • PipPipPipPipPipPipPip
  • 119 posts

Posted 08 February 2005 - 11:07 AM

Heh, nice one :D.
It's a very simple, yet usefull program :D

#8 LuciferStar

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 114 posts
  • Location:Suzhou Jiangsu China

Posted 08 February 2005 - 12:37 PM

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.

#9 maddog39

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 208 posts
  • Location:LI, New York
  • Interests:Web programming, computer programming, computer games, and Play Station2. :D

Posted 08 February 2005 - 05:15 PM

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

#10 Xedos

    Give me Reputation and i'll give you some back.

  • Banned
  • 203 posts
  • Location:Wirral, Northwest England
  • Interests:Interweb, Weebl and Bob, Linux, Windows, Nereks.

Posted 08 February 2005 - 05:43 PM

Nice, simple, useful program.

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




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users