In PHP
I would like to use the $num
value that is entered in the first form and execute a pow()
function with $num
and another variable, named $rate
, which I enter in the second form.
<body>
<form action="" method="post">
Enter number: <input type="number" name="num" id="num"/>
<input type="submit" name="next" value="Next"/><br>
</form>
<?php if( isset($_POST['next']) ) : $num = $_POST['num']; ?>
Entered number: <input type="text" name="entered" id="entered" value=" <?=$num ?> "/>
<?php endif; ?>
<form action="" method="post">
Enter rate: <input type="number" name="rate" id="rate"/>
<input type="submit" name="calculate" value="Calculate"/>
</form>
<?php if( isset($_POST['calculate']) ) : $rate = $_POST['rate'];
if( $rate >=1 && $rate <=10 ) : echo pow($num, $rate); endif;
endif;
?>
</body
When the code is executed it shows me:
Notice: Undefined variable: num in ... on line ...
0
What I need to add in the code to recognize the $num
variable and execute right the pow()
?
NB: Don't pay attention to the 'entered' input - it's just for a test.