Sorry for the vauge title, but I'm not quite sure what's the matter. I know it's some kinda setting. Here's the problem. I'm
learning PHP on my home computer, so I setup Apache 2.0.55, PHP 5, and MySQL 5.0
The first program using form submitting gave me errors. I know the code is right, I tested it on a known good server. The
form is at http://www.orderofatlas.com/calculate_form.html (this is the known good, so it won't return the errors from
there) When you submit blank values it should return you to the form, however, when I do this on my computer it gives me this
Notice: Use of undefined constant val3 - assumed 'val3' in C:\web\calculate.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\web\calculate.php:2) in
C:\web\calculate.php on line 3
when you actually enter values it gives you
Notice: Use of undefined constant val3 - assumed 'val3' in C:\web\calculate.php on line 2
Notice: Use of undefined constant val2 - assumed 'val2' in C:\web\calculate.php on line 2
Notice: Use of undefined constant calc - assumed 'calc' in C:\web\calculate.php on line 2
Notice: Use of undefined constant calc - assumed 'calc' in C:\web\calculate.php on line 6
Notice: Use of undefined constant val3 - assumed 'val3' in C:\web\calculate.php on line 7
Notice: Use of undefined constant val2 - assumed 'val2' in C:\web\calculate.php on line 7
The Result of the calculation is: 3
You'll notice the calculator actually works and gives the correct answer. Here's the code incase it makes a difference
<html>
<head>
<title>Calculation Form</title>
</head>
<body>
<form method="post" action="calculate.php">
<p>Value 1: <input type="text" name="val3" size="10"></p>
<p>Value 2: <input type="text" name="val2" size="10"></p>
<p>Calculation:<br>
<input type="radio" name="calc" value="add"> add<br>
<input type="radio" name="calc" value="subtract"> subtract<br>
<input type="radio" name="calc" value="multiply"> multiply<br>
<input type="radio" name="calc" value="divide"> divide<br>
<p><input type="submit" name="submit" value="calculate"></p>
</form>
</body>
</html>
The PHP side...
<?
if (($_POST[val3] == "") || ($_POST[val2] == "") || ($_POST[calc] == "")) {
header("Location: calculate_form.html");
exit;
}
if ($_POST[calc] == "add") {
$result = $_POST[val3] + $_POST[val2];
} else if ($_POST[calc] == "subtract") {
$result = $_POST[val3] - $_POST[val2];
} else if ($_POST[calc] == "multiply") {
$result = $_POST[val3] * $_POST[val2];
} else if ($_POST[calc] == "divide") {
$result = $_POST[val3] / $_POST[val2];
}
?>
<html>
<head>
<title>Calculation Result</title>
</head>
<body>
<p>The Result of the calculation is: <? echo "$result"; ?></p>
</body>
</html>
Like I said, I tested this and it works, so it has to be some kind of setting on my server, I just don't know what or where
to begin. Thanks in advance to anyone that can point me in the right direction.
-Mike