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

<?php
echo $_GET["username"]
 ?>

Notice: Undefined variable: name in C:\xampp\htdocs\phplessons\index.php on line 26

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

Thank you in advance for every answer.

  • 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. – RiggsFolly Apr 08 '20 at 16:36

1 Answers1

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:

<?php
   if(isset($_GET['username'])){
       echo $_GET["username"];
   }

?>
Elman Huseynov
  • 1,127
  • 1
  • 8
  • 18