last time i made simple calculator for my exercise, and its works good. but today when i open the codes again and run it in my browser, something strange happen. here is my html code:
<html>
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<form method="post" action="disp_form.php">
<p>First Value:<br/>
<input type="text" id="first" name="first">
</p>
<p>Second Value:<br/>
<input type="text" id="second" name="second">
</p>
<select method="post" name="group1">
<option name="group1" id="add" value="add"><p>+</p><br/>
<option name="group1" id="subtract" value="subtract"><p>-</p><br/>
<option name="group1" id="times" value="times"><p>x</p><br/>
<option name="group1" id="divide" value="divide"><p>/</p><br/>
</select>
<p></p>
<button type="submit" name="answer" id="answer"
value="answer">Calculate</button>
</form>
</body>
</html>
and this my php code
<?php
$first = $_POST['first'];
$second= $_POST['second'];
$operator = $_POST["group1"];
switch($operator)
{
case "add":
echo "Answer is: " .$first + $second;
break;
case "subtract":
echo "Answer is: " .$first - $second;
break;
case "times":
echo "Answer is: " .$first * $second;
break;
case "divide":
echo "Answer is: " .$first / $second;
break;
}
?>
the strange is, when i use / & *,the output is correct (eg 2*5, output is "Answer is: 10). but when i use + & -, the output is incorrect. (eg 8+5, output is 5, and for 8-5, output is -5) i thought the first value for add and substract defined as zero, thats why its result -5 and 5. but how the times and divide is done right?