I need to substract from number A number B only if is clicked option(form) near number B. Then result multiple with number C.
But if option (form) near B is not clicked, then multiply only A with C.
Can someone write some tips?
to substract, i use this.....
$calc = ($_POST['numberA']-$_POST['NumberB']);
i need to use if? i have very poor php knowledges
may be any link where i can read?
calculator with conditions
Moderator: General Moderators
Re: calculator with conditions
Hi,
just read a general php tutorial to improve your php knownledge. Then the answer would be clear. (You have to use if to realize what you want).
just read a general php tutorial to improve your php knownledge. Then the answer would be clear. (You have to use if to realize what you want).
Re: calculator with conditions
I guess something like this:
<?php
//First to make the variables easier to use:
$a = $_POST['numberA'];
$c = $_POST['numberC'];
//Checks if B is set, if else, sets b=0 since a-0 wont change anything
//BTW, isset($variableName) checks if the variable exists, very useful function...
if(isset($_POST['numberB']))
{
$b = $_POST['numberB'];
}
else
{ $b = 0; }
//Returns the result
$result = ($a - $b) * $c;
echo $result;
?>
Might aswell be something wrong with the <form method="POST"> maybe...
Good luck!
<?php
//First to make the variables easier to use:
$a = $_POST['numberA'];
$c = $_POST['numberC'];
//Checks if B is set, if else, sets b=0 since a-0 wont change anything
//BTW, isset($variableName) checks if the variable exists, very useful function...
if(isset($_POST['numberB']))
{
$b = $_POST['numberB'];
}
else
{ $b = 0; }
//Returns the result
$result = ($a - $b) * $c;
echo $result;
?>
Might aswell be something wrong with the <form method="POST"> maybe...
Good luck!