Hello Everyone, I am new to PHP and trying to run this very simple code but it is giving me some absurd output. Details are here: OS: Windows 7 home premium PHP version: 5.3.8 Web server: IIS on windows 7 **************************************************************************** HTML file (calculate_form.html): <html> <head> <title>Calculation Form</title> </head> <body> <form method="post" action="calculate.php"> <p>Value 1: <input type="text" name="val1" 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</p> <p><input type="submit" name="submit" value="Calculate"></p> </body> </html> ********************************************************************************* PHP file (calculate.php): <?php if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) { header("Location: calculate_form.html"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2]; } echo <title>Calculation Result</title>; echo <br>The result of the calculation is: $result; echo <p><a href=\calculate_forum.html\ target=\_self\> Another</a>; ?> ********************************************************************************** The output i am getting on the browser is: Calculation Result; echo The result of the calculation is: $result; echo Another; ?> **********************************************************************************
Try this: <?php if ($_POST[val1] == "" || $_POST[val2] == "" || $_POST[calc] =="") { header("Location: calculate_form.html"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2]; } echo '<title>Calculation Result</title>'; echo '<br>The result of the calculation is: '.$result; echo '<p><a href="calculate_forum.html">Another</a>'; ?> PHP: