|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-11-29 03:31 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 21:00:01 2025 UTC |
Hi, i have written a small .php file which has two input boxes and an submit button. On the click of the submit button i am calling the same php page again. The form action attribute has been set accordingly and method has been set to "POST". when i open the page for the first time i get an error saying "Undefined index: txtUserName in C:\Inetpub\wwwroot\dataauth.php on line 16" But after the page is submitted the error does not come and i can see the value which i had entered as specified by the echo command. The code is as follows: <html> <body> <form action="DataAuth.php" method="POST"> <table cellspacing=1 cellpadding=1> <tr> <td>User Name</td><td><input type="text" name="txtUserName"></td> </tr> <tr> <td>Password</td><td><input type="text" name="txtPassword"></td> </tr> <tr><td> </td></tr> <tr> <td><input type="submit"></td> </tr> </table> <?php echo $_POST["txtUserName"]; ?> <?php echo $_POST["txtPassword"]; ?> <?php $auth = false; // Assume user is not authenticated if (isset($PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { $dbc = new COM("ADODB.Connection"); $dbc->Provider = "Microsoft.JET.OLEDB.4.0"; $dbc->Open("C:\Afrea Final\Data\RegAfrea.mdb"); $rs = $dbc->Execute("select Title,surname,Firstname from Registration where surname='$PHP_AUTH_USER' AND firstname='$PHP_AUTH_PW'"); if ($rs->Recordcount==0) { $auth = false; } else { $auth = true; } $rs->Close(); } if ( ! $auth ) { header( 'WWW-Authenticate: Basic realm="Private"' ); header( 'HTTP/1.0 401 Unauthorized' ); echo 'Authorization Required.'; exit; } else { echo '<P>You are authorized!</P>'; } ?> </form> </body> </html> Can i know the reason why and how can i prevent this error from coming when the page is displayed for the first time. Thanks Manu