I have a problem with the work with variables from one condition in the second condition. I have something like that:
<form name="exampleForm" method="post">
...
<input type="submit" name="firstSubmit" value="Send">
<input type="submit" name="secondSubmit" value="Show">
</form>
<?php
if(isset($_POST['firstSubmit'])) {
function a() {
$a = 5;
$b = 6;
$c = $a + $b;
echo "The result is $c";
return $c;
}
$functionOutput = a();
}
if(isset($_POST['secondSubmit'])) {
echo $functionOutput;
}
?>
When I need to work with variable $functionOutput from first condition I always get an error message (undefined variable). How I can solve this problem?
Should fix it. It’s happening because you’re declaring $functionOutput inside your first IF statement.