I'm currently learning PHP from the very basic and started following a 2 year old youtube video. I'm trying to make a simple php calculator based from his code, but I've run into an error despite copying 100% of the example code, I'm guessing this is due to the version difference. What can be done to fix this issue, error code says undefined array, does this mean that I just need to pre-define the variables? How would I do this.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="site.php" method="get">
<input type="number" name="num1">
<br>
<input type="number" name="num2">
<br>
<input type="submit">
</form>
Answer: <?php echo $_GET["num1"] + $_GET["num2"] ?>
</body>
</html>
$_GETarray will be empty and you'll get the error you're seeing. The$_GETvariables will only exist when the form is actually submitted.