0
<?php
$txt = $_POST['username'];
echo $txt;

?>

<!DOCTYPE html>
<html>

<body>

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

<input name="username">
<input type="submit">

</form>

</body>

What I want it to do is echo the text when the form is submitted, but all it does is give me the error "Warning: Undefined array key "username" in C:\xampp\htdocs\index.php on line 2". It displays that message on the page as well, so it is very annoying.

  • https://stackoverflow.com/a/1372163/5947043 is what you need. Otherwise it'll try to read from the POST variables even when you just load the page (which is always a GET). The $_POST info is only available when the form is actually being submitted. – ADyson Feb 25 '21 at 23:26

0 Answers0