Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 178
0 Users 2 Guests Online

Calculator in PHP

This is a very simple task, But it is really good to all you newbies out there.

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?

if(!$submit1 && !$submit && !$submit2 && !$submit3){

?>
<html>
<head>
<h1><center><font color=blue>Zayne's Calculator</font></h1></center>
</head>
<body bgcolor=black text=yellow>
<p>
Welcome to the calculator version 2, I hope you can find any sums you want. Thank you.
<form action="" method=post>
<input type=text name=text>
<input type=text name=text1>
<input type=submit name=submit value=Add>
<input type=submit name=submit1 value=Minus>
<input type=submit name=submit2 value=Divide>
<input type=submit name=submit3 value=Multiply>
</body>
</html>
<?
}elseif($submit){
$very=$text+$text1;
echo 
"$text+$text1=$very";
echo 
"<body bgcolor=black text=yellow>Thank you for calculating<a href=index.php>Back</a>";
}elseif(
$submit1){
$mery=$text-$text1;
echo 
"$text-$text1=$mery";
echo 
"<body bgcolor=black text=yellow>Thank you for calculating<a href=index.php>Back</a>";
}elseif(
$submit2){
$fery=$text/$text1;
echo 
"$text/$text1=$fery";
echo 
"<body bgcolor=black text=yellow>Thank you for your calculating<a href=index.php>Back</a>";
}elseif(
$submit3){
$bery=$text*$text1;
echo 
"$text*$text1=$bery";
echo 
"<body bgcolor=black text=yellow>Thank you for your calculating<a href=index.php>Back</a>";
}

?>

Notice I did not put $_POST['example'], I just did it the short way by puttong a $ symbol in from of the html name. This can be done, Howevere it is more secure to use $_POST.
In php, It is basicaly just a language that interacts with forms. You put the value of a textbox into a variable and php reads it from there. You can then insert anything you want.
An example of sticking a texbox into a variable is. <input type=text name=text> This will be $_POST['text']. Lots of beginners battle with that. From there when i converted those to variables i used alot of operators, which are used to transform the values of the variables.
Im good for one on one tutoring.

Mail me at kfrauendorf@hotmail.com
Nyaz
Author:
Views:
2088
Rating:
Posted on Monday 15th October 2007 at 07:53 PM
Arudis
Arudis
put this script anywhere you want the calculator you show lol
Posted on Monday 15th October 2007 at 05:55 PM
rizwan1980pat
rizwan1980pat
WHERE TO ENTER THIS SCRIPTS, SO THAT WE CAN MAKE USE OF IT.