I need help to know if what Im doing is correct. I want to print the results as for example
3+4 = 7
but when I run the code I get 3 add 4 = 7.
I dont know if im using correctly the syntax echo "
The result is $num1 $operation $num2 = $result
";
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Calculation Result</title>
</head>
<body>
<?php # handle_form.php
// Create a shorthand for the form data:
//retrieve the data by using $_REQUEST and name of the textbox
$num1 = $_REQUEST['number1'];
$num2 = $_REQUEST['number2'];
$operation = $_REQUEST['operation'];
//
//you code starts from here
//validation of the input using is_numeric() function
if(is_numeric($num1))
{
$num1 = (int)$num1; // int number1
}
if(is_numeric($num2))
{
$num2 = (int)$num2; // int number2
}
if ($operation=='add') {
$result = $num1 + $num2;
}
elseif ($operation=='substract') {
$result = $num1 - $num2;
}
elseif ($operation=='multiple') {
$result = $num1 * $num2;
}
elseif ($operation=='divide') {
$result = $num1 / $num2;
}
// Print the submitted information:
echo "<p> The result is $num1 $operation $num2 = $result <p>";
?>
</body>
</html>