From:             [EMAIL PROTECTED]
Operating system: Windows 98
PHP version:      4.2.3
PHP Bug Type:     *General Issues
Bug description:  Error when accessing value of the textbox

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>&nbsp;</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

-- 
Edit bug report at http://bugs.php.net/?id=20714&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20714&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20714&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20714&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20714&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20714&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20714&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20714&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20714&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20714&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20714&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20714&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20714&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20714&r=isapi

Reply via email to