I’m a moderate PHP coder, but I’m not into the more complicated stuff yet. I’m taking Internet Programming and Development class right now, and we have to create this example that has two pages. The first page is a form where the user inputs two numbers and then clicks one of four radio buttons (addition, subtraction, multiplication, or division) before hitting Submit. On the results page, the two numbers are shown with the operation sign of whichever operation they chose on the previous page (i.e. addition) with the answer to the problem (i.e. 8 / 2 = 4). I’m having trouble getting it to work on the results page, and I can’t figure it out. Here’s the codes to the pages:
Form Page:
<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“
<html xmlns=”
<head>
<title>
2910_22.php
</title>
</head>
<body>
[code here admitted, note saying author’s name (me)]
<form method=”post” action=”2910_22_get.php” name=”form1″>
Enter #1: <input type=”text” name=”num1″ /> <br />
Enter #2: <input type=”text” name=”num2″ /> <br />
<input type=”radio” name=”add” value=”add” />Addition <br /> <!–purpose: add–>
<input type=”radio” name=”add” value=”sub” />Subtraction <br /> <!–purpose: sub–>
<input type=”radio” name=”add” value=”mult” />Multiplication <br /> <!–purpose:mult–>
<input type=”radio” name=”add” value=”div” />Division <br /> <!–purpose:div–>
<input type=”submit” value=”submit” />
</form>
</body>
</html>
Results Page:
<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“
<html xmlns=”
<head>
<title>
2910_22_get.php
</title>
</head>
<body>
[code admitted for same reason as above]
<?php
$num1=$_POST[‘num1’];
$num2=$_POST[‘num2’];
$radio=$_POST[‘add’];
if ($radio == add)
{
$y=$num1 + $num2;
echo $num1.” + “.$num2.” = “.$y;
}
elseif ($radio == sub)
{
$y=$num1 – $num2;
echo $num1.” – “$num2.” = “.$y;
}
elseif ($radio == mult)
{
$y=$num1 * $num2;
echo $num1.” X “.$num2.” = “.$y;
}
else
{
$y=$num1 / $num2;
echo $num1.” / “.$num2.” = “.$y;
}
?>
</body>
</html>
The results page, at this time, doesn’t output anything (blank page). Any help would be greatly appreciated.