i always get the notice "Undefined index: txtP in D:\WampWorkbench\xampp\htdocs\Test\Login.php on line 15" on the first time i run my site...
Untitled Document
Three answers:
Greig Ritchie
2011-08-04 03:09:54 UTC
because $w has not been defined until the user inputs the variable value ( the login name )
Jacques
2011-08-04 10:31:13 UTC
It's good practice when you assign php variables to make sure they have a value, so that if they don't have a value you can direct people back to the main page with a specific error message or check if a value has been added.
use the isset command, like this:
if (isset($_POST['txtP']){
$w=$_POST['txtP'];
echo $w;
} else {
echo "You need to fill out the form."; //can be any error message.
}
bluedee_2811r
2011-08-04 10:19:36 UTC
That's error is just general error. It is caused because you have not entered value into the form you made. You can ignore it anyway in development mode. But should turn off the message if you want to deploy your website by inserting this code
error_reporting(E_ALL ^ E_NOTICE); // Report all errors except E_NOTICE
OR
error_reporting(0); // turn off all error messages
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.