Home > Software engineering >  Why do I get "undefined array key" when trying to get values from HTML forms?
Why do I get "undefined array key" when trying to get values from HTML forms?

Time:10-23

I have attached the code samples of my html and php files along with the error I'm getting whenever I try to run the code to get values entered in my html form to my php document. I'm using the XAMPP server.

I have done this exactly as mentioned in the site mentioned below: https://www.w3schools.com/php/php_forms.asp

I would really appreciate it of someone could help me out with this.

HTML SAMPLE:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>

<form action="welcome.php" method="POST">

 Name : <input type="text" name="name"> <br><br>
 E-mail: <input type="text" name="email"><br> <br>
 <input type="submit">

</form>
</body>
</html>

 PHP SAMPLE:

 <!DOCTYPE html>
 <html>
 <body>

Hello <?php echo $_POST['name']; ?>
Your email address is <?php echo $_POST['email']; ?>


</body>
</html>

ERROR in my browser:

Warning: Undefined array key "name" in C:\xampp\htdocs\BasicIntro\welcome.php on line 5 Your email address is

Warning: Undefined array key "email" in C:\xampp\htdocs\BasicIntro\welcome.php on line 6

CodePudding user response:

Both pages are working. no mistakes. I dont know why it does not work for you. Try reinstalling XAMPP.

  • Related