Solution 1 :

Your variable will be created only after submitting the form. That is why in the code you need to make a check-up and only then show that variable. Try like this:

       echo $_GET["username"];


Problem :

<form action="site.php" method="get">
 Name: <input type="text" name="username">
 <input type="submit">

echo $_GET["username"]

Notice: Undefined variable: name in C:xampphtdocsphplessonsindex.php on line 26

After filling in the answer will be displayed.
Object was not found!

Thank you in advance for every answer.


Comment posted by RiggsFolly

You have to first test that the form has been submitted. The first time the page loads, it wont have been submitted and $_GET[‘userbame”] will not exist.

Comment posted by RiggsFolly

Do or Do Not, there is no “Try” padawan. A

Comment posted by Elman Huseynov

@RiggsFolly updated answer, added explanation.

Comment posted by Funk Forty Niner

Proper bracing and closing should be used also.

Comment posted by Elman Huseynov

@FunkFortyNiner also added that.

Comment posted by Funk Forty Niner

@ElmanHuseynov I noticed 😉


Leave a Reply

Your email address will not be published. Required fields are marked *