This was just a little project I made in one of my classes. The teacher teaches nothing and just gives us a .PDF full of VB and HTML code. It only works in IE anyway. But I went off did my own in PHP.
Also sorry to chili, in his thread I mentioned the teacher used ASP.NET. That what was originally but then he changed to online VB, that's my fault sorry.
This script was made in about 60 minutes and the teacher is really easy so I made it as basic as possible.
There are two files.
Here is the first one.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mathematical Calculator</title> </head> <body> <center> <form method="POST" action="action.php"> <p>First number: <input type="text" name="val1" /> <br /> Second number: <input type="text" name="val2" /><br /> <input type="radio" name="opt" value="add"/> Addition <br /> <input type="radio" name="opt" value="sub"/> Subtract <br /> <input type="radio" name="opt" value="mul"/> Multiply <br /> <input type="radio" name="opt" value="div"/> Divide </p> <p> To the power of: <input type="text" name="powernum" /><br /> <input type="radio" name="power" value="power2"/> Power of 2 <br /> <input type="radio" name="power" value="power3"/> Power of 3 </p> <input type="submit" value="Submit" name="submit" /> </form> </center> </body> </html>
Now here is the second.
<?php
$val1 = $_POST['val1'];
$val2 = $_POST['val2'];
$option = $_POST['opt'];
$powerval = $_POST['power'];
$powernum = $_POST['powernum'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mathematical Calculator</title>
</head>
<body>
<?php
if ($option == add) {
$answer = $val1 + $val2;
}
if ($option == sub) {
$answer = $val1 - $val2;
}
if ($option == mul) {
$answer = $val1 * $val2;
}
if ($option == div) {
$answer = $val1 / $val2;
}
if ($powerval == power2) {
$answerpower = $powernum * $powernum;
}
if ($powerval == power3) {
$answerpower = $powernum * $powernum * $powernum;
}
echo "<br />";
if ($option == add) {
echo "$val1 + $val2 <br />";
echo "$answer";
}
if ($option == sub) {
echo "$val1 - $val2<br />";
echo "$answer";
}
if ($option == mul) {
echo "$val1 * $val2<br />";
echo "$answer";
}
if ($option == div) {
echo "$val1 / $val2<br />";
echo "$answer";
}
echo "<br />";
if ($powerval == power2) {
echo "$powernum * $powernum<br />";
echo "$answerpower";
}
if ($powerval == power3) {
echo "$powernum * $powernum * $powernum<br />";
echo "$answerpower";
}
?>
<center>
<form method="POST" action="action.php">
<p>First number: <input type="text" name="val1" /> <br />
Second number: <input type="text" name="val2" /><br />
<input type="radio" name="opt" value="add"/> Addition <br />
<input type="radio" name="opt" value="sub"/> Subtract <br />
<input type="radio" name="opt" value="mul"/> Multiply <br />
<input type="radio" name="opt" value="div"/> Divide
</p>
<p>
Number: <input type="text" name="powernum" /><br />
<input type="radio" name="power" value="power2"/> Power of 2 <br />
<input type="radio" name="power" value="power3"/> Power of 3
</p>
<input type="submit" value="Submit" name="submit" />
</form>
</center>
</body>
</html>
This is just a basic one as I explained above.
You input two values and select a radio button. You then click on the submit button and it show the operation and the answer of what you chose.
For more a advanced one check out Chili5's PHP Calculator Script here.


Sign In
Create Account


Back to top









