Here is my script. any help would be greatly appreciated.
thanks,
<?php
//--------------------------------------------------------------------------------------------//
// I"m trying to create a calculator script that enables the user to submit two numbers and //
// choose an operation (addition, multiplication, division, or subtraction) //
// to perform on them. //
//-------------------------------------------------------------------------------------------//
//---------------------------//
// Define Variables //
//--------------------------//
$num1 = "$_POST[num1]";
$num2 = "$_POST[num2]";
$calculate = "$_POST[math_func]";
$results = "";
settype($num1, 'double');
settype($num2, 'double');
//-----------------------------------//
//Begin Validation Section //
//-----------------------------------//
//change default php error number in ini file or script
ini_set("error_reporting", E_ALL);
if (!isset($num1,$num2)){
$results = "PLEASE INPUT 2 NUMBERS and SELECT AN OPERATION TO PERFORM";
}
// ---------------------------------//
// Define Math Functions //
//---------------------------------//
function addNum($num1, $num2){
global $num1;
global $num2;
$results = $num1 + $num2;
return $results;
}
function subNum($num1, $num2){
global $num1;
global $num2;
$results = $num1 - $num2;
return $results;
}
function multiNum($num1, $num2) {
global $num1;
global $num2;
$results = $num1 * $num2;
return $results;
}
function divideNum($num1, $num2) {
global $num1;
global $num2;
$results = $num1 / $num2;
return $results;
}
//----------------------------------//
// Calculation Script //
//---------------------------------//
if ($calculate == "add_it") {
addNum($num1,$num2);
echo "$results";
} else if ($calculate == "sub_it") {
subNum($num1, $num2);
echo "$results";
} else if ($calculate == "multi_it") {
multiNum($num1, $num2);
echo "$results";
} else {
if ($num2 <= 0) {
// Denominator cannot be less than or equal to 0
$results = "You cannnot have a zero as a denominator";
} else {
divideNum($num1, $num2);
echo "$results";
}
}
//---------------------------------//
// End of Script //
//---------------------------------//
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Adobe GoLive" />
<title>Basic Calculator Script</title>
</head>
<body bgcolor="#ffffff">
<form action="<?php echo $_SERVER[PHP_SELF] ?>" method="POST">
<b><u>Calculator Script</u></b><br>
<table>
<tr>
<td><strong>Number 1:</strong><input type="text" name="num1"><br><strong>Number 2:</strong><input type="text" name="num2"></td>
<td><select name="math_func">
<option value="add_it"> +</option>
<option value="sub_it"> -</option>
<option value="multi_it"> *</option>
<option value="div_it"> /</option>
</select></td>
</tr>
</table>
<input type="Submit" value="compute">
</form>
<br>Results: <?php echo $results ?>
<p></p>
</body>
</html>