That code was written years ago when we used a built in PHP function called Register Globals.
Notice in the first script that we have an input tag with name="val1" and another with name="val2". When you hit the button named "Calculate", the values entered in those fields need to be sent (passed) to the PHP script.
Back when we used to use Register Globals, PHP would automatically make a variable called $val1 and $val2 and a third called $calc. While this was very convenient, it was also a security risk so PHP usually doesn't use Register Globals anymore. The values are still passed from your form to the PHP sript - we just skip the part where we automatically make variables (like $val1 in your exmaple).
So one solution would be to turn Register Globals back on and your script will start working. Don't do this. This would be bad. A responsible sysadmin won't do this for you.
The right solution is to manually convert the values into variables.
Notice that your form says: method="post". This is specifying how the data is being sent from your form to your PHP script. You need to know the method so that you know how to acquire the incoming data.
Since your form is using the POST method, you can get the incoming data from the form fields in a variable called $_POST like this:
$val1 = $POST['val1'];
$val2 = $POST['val2'];
$calc = $_POST['calc'];
This means, find the data that came from the form in the "val1" field and put it in a variable called $val1. Same with val2 and calc.
If you put those lines in your PHP script, your script will work. That's one way to solve the problem. Another way that some people would say is better would be to change all the variables (like $val1) to the form that they are received in (such as $_POST[val1']) like this:
if( is_numeric($_POST['val1']) && is_numeric($_POST['val2']) )
instead of
if( is_numeric($val1) && is_numeric($val2) )
This technique will save memory which will be important to you as your scripts become more complex.