将变量从一种形式用于另一种形式时出错

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.

This is the solution I found yesterday and it works pretty well. Hope to be well understandable.

<?php   if( empty($_POST) ): ?>
<form action="" method="post">
    Enter number: <input type="number" name="num" id="num"/>
    <input type="submit" name="next" value="Next"/><br>
</form>
<?php   endif; ?>

<?php   if( isset($_POST['next']) ) : $num = $_POST['num']; ?>
<form action="" method="post">
    Entered number: <input type="text" name="entered" id="entered" value=" <?=$num ?> "/><br>
    Enter rate: <input type="number" name="rate" id="rate"/>
    <input type="submit" name="calculate" value="Calculate"/>
</form>
<?php   endif;

    if( isset($_POST['calculate']) ) : $rate = $_POST['rate'];
        $num = $_POST['entered']; 
        if( $rate >=1 && $rate <=10 ) : echo pow($num, $rate); 
        else: echo 'Enter rate between 1 and 10' . '<form> <input type="submit" value="Back" onClick="history.go(-1);return TRUE;"> </form>';
        endif;
    endif;
?>