First of all, it's not clear why you use
method="GET"
and
$_GET
; by your semantic, it should rather be
method="POST"
and
$_POST
.
But this is not a problem. The problem is different.
Please see my comment to the question. It looks like you show fragment of one single file. If this file was not "index.php", it would not work at all. But if it, it would not work when the page is just loaded. At this moment, the HTTP request with
name
and
age
is not yet sent, so the indices are not yet defined. When you submit the form, the HTTP request will come with these two indices, so your script will receive them as values by defined indices.
The simplest thing you can do is the check-up of the index in
$_GET
or
$_POST
. This is one of the ways to do so:
http://php.net/manual/en/function.array-key-exists.php[
^].
—SA