Hi all,

I am new to php and I have a problem that I am looking into it for 1 day and can't understand it please help.

here is my html code :

<title> Calculation Form </title>

<form action=calculate.php method="POST">

value one: <input type="text" name"val1" size=10 /><br />
value two: <input type="text" name"val2" size=10 /><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="devide"> devide</p>

<p><input type="submit" name="submit" value="calculate"></p>



It calls the calculate.php

it has 2 text boxes and 4 radio buttons that 4 simple calculation funtions

here is my php code


if (isset($_POST['submit'])) {

$selected_radio = "";
$selected_radio = $_POST['calc'];

if ($selected_radio == 'add') {
$total= ($_POST['val1'] + $_POST['val2']);
else if ($selected_radio == 'subtract') {
$total= ($_POST['val1'] - $_POST['val2']);
else if ($selected_radio == 'mutiply') {
$total= ($_POST['val1'] * $_POST['val2']);
else if ($selected_radio == 'devide') {
$total= ($_POST['val1'] / $_POST['val2']);

echo $total;


and I get result such as add0 subtract0 and so on ...

First of all, I have no idea where that 0 come from. I echoed every thing for testing purposes and every thing shows fine. I also can't get the values inside the text boxes by using ($_POST['val1'];)

Please help, this is so frustrating for me ...

Thanks a lot,

5 Years
Discussion Span
Last Post by broj1

The problem is in lines 7 and 8 of the html file. You are missing '=' sign when assigning name attributes to input elements. This is the correct code:

value one: <input type="text" name="val1" size=10 /><br />
value two: <input type="text" name="val2" size=10 /><br />

The easiest way to spot these kinds of errors is to look at the source code in the browser (in Firefox left click on the page and select View page source). Html errors are marked red.

Votes + Comments
you rock

There is another typo in the calculate.php file on line 18: you are missing letter 'l' in a word multiply. The correct code is

else if ($selected_radio == 'mutiply') {

Sorry, correct code is

else if ($selected_radio == 'multiply') {

This forum has been upgraded just recently and I can not find the edit button that is why so many posts from me :-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.