Forum Moderators: coopster

Message Too Old, No Replies

php script error

         

gthri

9:31 am on May 10, 2005 (gmt 0)

10+ Year Member



ihave a php page which displays error as

Notice: Undefined index: username in c:\program files\easyphp1-8\www\inc\auth.php on line 16

Notice: Undefined index: password in c:\program files\easyphp1-8\www\inc\auth.php on line 16

the code is as:

if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}

// query for a user/pass match
$result=mysql_query("select * from login
where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'");

// retrieve number of rows resulted
$num=mysql_num_rows($result);

// print login form and exit if failed.
if($num < 1){
echo "You are not authenticated. Please login.<br><br>

<form method=POST action=index3.php>
username: <input type=text name=\"username\">
password: <input type=password name=\"password\">
<input type=submit>
</form>";

exit;
}
?>

can anyone let me know whts the problem?

buriedUnderGround

10:42 am on May 10, 2005 (gmt 0)

10+ Year Member



this isn't an error as such, it's only a notice telling you that there are variables being refered to that have not been set.
After the form has been submitted the variables are created/set, so the notice goes away.
If you want it to go away permanently (for this script) try a different setting for error_reporting() at the beginning of your code.

ergophobe

6:06 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld gthri

Better than turning down error reporting is to always test for values.

So

if (isset($_SESSION['username']) && $_SESSION['username'] = 'somename')

will never give you the undefined index notice.