Loading...


bookmark - Php Calculator Simple but cool.

Php Calculator - Simple but cool.

 
 Discussion by maddog39 with 21 Replies.
 Last Update: October 7, 2011, 7:30 am ( View Rated (1) )
 
bookmark - Php Calculator Simple but cool.  
Quickly Post to Php Calculator Simple but cool. w/o signup Share Info about Php Calculator Simple but cool. using Facebook, Twitter etc. email your friend about Php Calculator Simple but cool. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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

   Sun Feb 6, 2005    Reply         

QUOTE (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. :D




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

   Sun Feb 6, 2005    Reply         

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.

   Sun Feb 6, 2005    Reply         


Lol, thanks guys. :D

   Sun Feb 6, 2005    Reply         

cool but a bit pointless :D :D

   Mon Feb 7, 2005    Reply         

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

   Tue Feb 8, 2005    Reply         


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

   Tue Feb 8, 2005    Reply         

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.

   Tue Feb 8, 2005    Reply         

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

   Tue Feb 8, 2005    Reply         

Nice, simple, useful program.

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

   Tue Feb 8, 2005    Reply         

QUOTE (Xedos)

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

   Tue Feb 8, 2005    Reply         

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 :D )

   Tue Feb 8, 2005    Reply         

QUOTE (Xedos)

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


YES!
but not to do such a thing.

   Wed Feb 9, 2005    Reply         

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

   Thu Feb 10, 2005    Reply         

QUOTE (Xedos)

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

   Fri Feb 11, 2005    Reply         

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.

   Fri Feb 11, 2005    Reply         

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

   Thu Feb 24, 2005    Reply         

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

   Mon Sep 1, 2008    Reply         

[font="Tahoma"]
The front-end HTML code for my PHP | Calculator is the same as yours but my back-end PHP scripting code differs a little from yours. This is what it I have. What mazes me is that I am not able to successfully run the script, thus, ending up with the PHP parser annoying me with its tedious error scripts. Please, try and help me out if you can. Thank you! :-)
[/font]

[php]
<?php
if (($_POST[Value-1] = "") || ($_POST[Value-2] = "") || ($_POST[Calc] =""))
{
header("Location: caculator.html");
exit;
}
if ($_POST[Calc] == "Add")
{
$result = $_POST[Value-1] + $_POST[Value-2];
}
else if ($_POST[Calc] == "Subtract")
{
$result = $_POST[Value-1] - $_POST[Value-2];
}
if ($_POST[Calc] == "Divide")
{
$result = $_POST[Value-1] / $_POST[Value-2];
}
else if ($_POST[Calc] == "Multiply")
{
$result = $_POST[Value-1] * $_POST[Value-2];
}
?>
<html>
<head>
<title>
PHP | Calculator
</title>
</head>
<body>
<div align="center">
<p>The result of the computation was
<?php
echo ("$result");
?>
</p>
<a href="calculator.html">Back</a >
</div>
</body>
</html>
[/php]

   Sat Mar 19, 2011    Reply         

Fun little toy lol nice work

   Sun Mar 27, 2011    Reply         

Can anyone help me with the code for a simple php calculation that I can paste into my wordpress blog?

It only has one numerical input field I should think it would take someone who knows how under 10 mins to create the code which I would just want to paste into the wordpress page...

The customer types in a number (relating to years in this case)

i.e

Over ____ Years

and then then hits CALCULATE.

Answer ___________

The no. of years must then be multiplied by £1500 with an additional £1500 being added on top. i.e 10 years = £16,500


Let me know if you feel you can help...

   Wed May 25, 2011    Reply         

hi, i am new with php. can you help me fix my script problems? its errors is 'undefined variable. how do i define variable? the script works best only with quality() but not others. please. thanks in advance.


CODE

<?PHP
$result=$_POST['day'];
$pv=$_POST['pv'];
$av=$_POST['av'];
$rr=$_POST['rr'];
$no=$_POST['no'];
$tt=$_POST['tt'];
$downtime=$_POST['downtime'];

if(!$_POST['day'])
{
echo '
<form method="post" action="'.$_SERVER['PHP_SELF'].'">

<select name="day">
<option value="mon">Monday</option>
<option value="tue">Tuesday</option>
<option value="wed">Wednesday</option>
<option value="thu">Thursday</option>
<option value="fri">Friday</option>
<option value="sat">Saturday</option>
<option value="sun">Sunday</option>
</select><br />
<td>Planned Volume:</td>
<input type="text" name="pv" size="5"><br />
<td>Actual Volume:</td>
<input type="text" name="av" size="5"><br />
<td>Reject/Rework:</td>
<input type="text" name="rr" size="5"><br />
<td>Nett Output</td>
<input type="text" name="no" size="5"><br />
<td>Takt Time</td>
<input type="text" name="tt" size="5"><br />
<td>Downtime</td>
<input type="text" name="downtime" size="5"><br />

<input type="submit" name="doit" value="calculate">
</form>
';
}else{
if($_POST['day'] == 'mon')
{
echo 'Your working hour is 495min';
$result=495 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}

if($_POST['day'] == 'tue')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}

if($_POST['day'] == 'wed')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}

if($_POST['day'] == 'thu')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}

if($_POST['day'] == 'fri')
{
echo 'Your working hour is 430min';
$result=430-$downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
}

function availability($result){
$count2= $result / $ppt;
$count3= $count2 * 100;
$count = number_format($count3, 0);
echo 'Availability percentage is'. "$count" . "%";
}

function performance($not, $tt, $av, $result){
$not = $av / $result;
$count4= $not / $tt;
$count5= $count4 * 100;
$count6= number_format($count5, 0);
echo 'Performance percentage is'. "$count6" . "%";
}

function quality($no, $av){
$count7= $no / $av;
$count8= $count7 * 100;
$count9= number_format($count8, 0);
echo 'Quality percentage is'. "$count9" . "%";
}

function oee($count2, $count4, $count7){
$count10= $count2 * $count4 * $count7;
$count11= $count10 * 100;
$count12= number_format($count11, 0);
echo 'OEE percentage is'. "$count12" . "%";
}







?>

   Fri Oct 7, 2011    Reply         

Quickly Post to Php Calculator Simple but cool. w/o signup Share Info about Php Calculator Simple but cool. using Facebook, Twitter etc. email your friend about Php Calculator Simple but cool. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Php Formmail Generator

PHP FormMail Generator QUOTEPHP FormMail Generator - A tool to create ready-to-use web forms in a flash. Once the form has been generated, you have a full functional web form. Including error checking of required fields, email address validation, credit card number & expiry date checking ...more

   22-Apr-2005    Reply         

Making Calculators with PHP

Yes, I made some basic calculators to use for simple math problems, nothing big. I'm a newbie at php, so if I made something that could be short, long, I am sorry. lol Here is one for adding two numbers. CODE<html> <title>Adding 2 numbers </ti ...more

   27-Jun-2008    Reply         

Cool Php And Sql Books?

Hey wanted to know if anyone can suggest any cool books for a beginner of PHP and Sql. I'm currently reading PHP and MySQL for Dummies it is pretty good and easy to follow. Im also reading online at www.w3schools.com. In some other thread someone suggested a book called Learn PHP in 24 hours, ...more

   27-Sep-2010    Reply         

Php Designer 2005 - By Far The Best One.. .. that was the description..   Php Designer 2005 - By Far The Best One.. .. that was the description.. (13) (9) New Php Forums!   New Php Forums!