NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > Webmaster Tutorials
Reload this Page Simple PHP Calculator

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search
0 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 04-05-2007, 03:11 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse

Simple PHP Calculator


Here is a simple PHP Calculator. I created it originally for an example on using classes but you can use it anyway you wish

PHP Code:
<?php
// Calculator Script v1
// Copyright (C) 2007 RageD

// Define to make this all one document
$page $_GET['page'];

// Defining the "calc" class
class calc {
     var 
$number1;
     var 
$number2;

          function 
add($number1,$number2)
          {
                   
$result =$number1 $number2;
                    echo(
"The sum of $number1 and $number2 is $result<br><br>");
                    echo(
"$number1 + $number2 = $result");
                    exit;
           }

          function 
subtract($number1,$number2)
          {
                   
$result =$number1 $number2;
                    echo(
"The difference of $number1 and $number2 is $result<br><br>");
                    echo(
"$number1 &#045 $number2 = $result");
                    exit;
           }

          function 
divide($number1,$number2)
          {
                   
$result =$number1 $number2;
????: NamePros.com http://www.namepros.com/webmaster-tutorials/313343-simple-php-calculator.html
                    echo(
"$number1 divided by $number2 is $result<br><br>");
                    echo(
"$number1 ÷ $number2 = $result");
                    exit;
           }

          function 
multiply($number1,$number2)
          {
                   
$result =$number1 $number2;
                    echo(
"The product of $number1 and $number2 is $result<br><br>");
                    echo(
"$number1 x $number2 = $result");
                    exit;
           }
}
$calc = new calc();
?>
<TITLE>PHP Calculator v1</TITLE>
<form name="calc" action="?page=calc" method="POST">
Number 1: <input type=text name=value1><br>
Number 2: <input type=text name=value2><br>
Operation: <input type=radio name=oper value="add">Addition <input type=radio name=oper value="subtract">Subtraction <input type=radio name=oper value="divide">Division <input type=radio name=oper value="multiply">Multiplication</input><br>
????: NamePros.com http://www.namepros.com/showthread.php?t=313343
<input type=submit value="Calculate">
</form>
<?php
if($page == "calc"){
$number1 $_POST['value1'];
$number2 $_POST['value2'];
$oper $_POST['oper'];
     if(!
$number1){
          echo(
"You must enter number 1!");
          exit;
     }
     if(!
$number2){
          echo(
"You must enter number 2!");
          exit;
     }
     if(!
$oper){
          echo(
"You must select an operation to do with the numbers!");
          exit;
     }
     if(!
eregi("[0-9]"$number1)){
          echo(
"Number 1 MUST be numbers!");
          exit;
     }
     if(!
eregi("[0-9]"$number2)){
          echo(
"Number 2 MUST be numbers!");
          exit;
     }
     if(
$oper == "add"){
          
$calc->add($number1,$number2);
     }
     if(
$oper == "subtract"){
          
$calc->subtract($number1,$number2);
     }
     if(
$oper == "divide"){
          
$calc->divide($number1,$number2);
     }
     if(
$oper == "multiply"){
          
$calc->multiply($number1,$number2);
     }
}
?>
Enjoy!

-RageD
RageD is offline  
Old 04-05-2007, 03:26 PM   #2 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Nice calculator.. You could add a few functions too it.. Such as round, sqrt, etc.

- Steve
__________________
I feel old.
iNod is offline  
Old 04-05-2007, 08:53 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse
If you would like me to I could do that. Like I said it was an example script to explain classes but I could expand

-RageD
RageD is offline  
Closed Thread


LinkBacks (?)
LinkBack to this Thread: http://www.namepros.com/webmaster-tutorials/313343-simple-php-calculator.html
Posted By For Type Date
CIS-2140 AB B+AWeek8 This thread Refback 11-03-2011 09:12 AM
Simple PHP Calculator - NamePros.com This thread Refback 10-04-2011 05:48 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 01:00 AM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger