[advanced search]
Results from the most recent live auction are here.
15 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Webmaster Tutorials
User Name
Password

Old 04-05-2007, 03:11 PM   · #1
RageD
Senior Member
 
Name: Dennis
Location: Joliet, Illinois
Trader Rating: (43)
Join Date: Apr 2005
Posts: 1,149
NP$: 349.10 (Donate)
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 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;
                    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>
<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


Please register or log-in into NamePros to hide ads
RageD is offline   Reply With Quote
Old 04-05-2007, 03:26 PM   · #2
iNod
Eating Pie
 
iNod's Avatar
 
Name: Steve
Location: Canada
Trader Rating: (66)
Join Date: Nov 2004
Posts: 2,284
NP$: 91.30 (Donate)
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
__________________
RegisterDub.com - 200th Customer Milestone
ZuneParts.net - International Zune Parts and Accessories
FeaturedFont.com - One Top Free Font a Day!
iNod is offline   Reply With Quote
Old 04-05-2007, 08:53 PM   · #3
RageD
Senior Member
 
Name: Dennis
Location: Joliet, Illinois
Trader Rating: (43)
Join Date: Apr 2005
Posts: 1,149
NP$: 349.10 (Donate)
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 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   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Buy Flash Arcade Game Script Find out how! Hunting Moon
Advertise your business at NamePros
All times are GMT -7. The time now is 10:06 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0