Nov 21, 2009
Pages: 1, 2

Php Calculator - Simple but cool.

free web hosting

Read Latest Entries..: (Post #17) by iGuest on Sep 1 2008, 10:30 AM.
Calculator in javascript Php Calculator I just checkout the calculator posted here by someonein in javascript ..But the problem is that it is showng the opreator in the text field also.So can any one send the code of calculator which dnt shw the operator in the text field and havn only the single text field-question by tarundeep singh...
read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Php Calculator - Simple but cool.

maddog39
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. biggrin.gif

 

 

 


Comment/Reply (w/o sign-up)

Cammy
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. biggrin.gif
*




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

 

 

 


Comment/Reply (w/o sign-up)

AnimeExile
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.

Comment/Reply (w/o sign-up)

maddog39
Lol, thanks guys. biggrin.gif

Comment/Reply (w/o sign-up)

krap
cool but a bit pointless wink.gif ph34r.gif

Comment/Reply (w/o sign-up)

nancmu
Good work, guy. smile.gif
That's a good once. wink.gif

Comment/Reply (w/o sign-up)

Deaths Aprentice
Heh, nice one smile.gif.
It's a very simple, yet usefull program smile.gif

Comment/Reply (w/o sign-up)

LuciferStar
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.

Comment/Reply (w/o sign-up)

maddog39
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. biggrin.gif

Comment/Reply (w/o sign-up)

Xedos
Nice, simple, useful program.

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

Comment/Reply (w/o sign-up)

Latest Entries

iGuest
Calculator in javascript
Php Calculator

I just checkout the calculator posted here by someonein in javascript ..

But the problem is that it is showng the opreator in the text field also.

So can any one send the code of calculator which dnt shw the operator in the text field and havn only the single text field



-question by tarundeep singh

Comment/Reply (w/o sign-up)

maddog39
Well guys since you asked anyway. I have made and posted a Javascript version thats I also believe is alot better. Its got tons more capabilities and stuff. I posted the code to. So just go to:

http://www.trap17.com/forums/Js-Calculator-t7499.html

Comment/Reply (w/o sign-up)

LuciferStar
Well,everybody,
we may conside that many things can be solved by many different ways.

What we may do is try to find the best neat path.

BTW,
PHP,JSP,ASP are server-side scripts,
Javascript,vbscript are client-side scripts.

Comment/Reply (w/o sign-up)

FaLgoR
QUOTE(Xedos @ Feb 8 2005, 02: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.
*



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....

Comment/Reply (w/o sign-up)

maddog39
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. laugh.gif tongue.gif biggrin.gif

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2

Searching Video's for php, calculator, simple, cool
See Also,
advertisement


Php Calculator - Simple but cool.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com