So I’ve been teaching myself php little by little and I tried to make a calculator. Now, I got the calculations correct however when I enter the numbers and click submit it shows the sum, difference, product, and quotient. I want to know how to tell it to only show one if that is chosen.
Php Code:[php]<?php
if ($_POST[‘submit_calc’ && ‘option1’]) {
$a=$_POST[‘1’];
$b=$_POST[‘2’];
$sum=$a+$b;
echo "Sum equals:".$sum."<br />";
}
if ($_POST[‘submit_calc’ && ‘option2’]) {
$a=$_POST[‘1’];
$b=$_POST[‘2’];
$dif=$a-$b;
echo "Difference equals:".$dif."<br />";
}
if ($_POST[‘submit_calc’ && ‘option3’]) {
$a=$_POST[‘1’];
$b=$_POST[‘2’];
$product=$a*$b;
echo "product equals:".$product."<br />";
}
if ($_POST[‘submit_calc’ && ‘option4’]) {
$a=$_POST[‘1’];
$b=$_POST[‘2’];
$quotient=$a/$b;
echo "quotient equals:".$quotient;
}
?>[/php]