Undefined variable error
Posted: Tue Oct 01, 2002 11:51 am
Hi people, i'm runing PHP4 on IIS5 as a CGI script. When i run the following authentication code, i get the "Notice: Undefined variable: password in c:\inetpub\wwwroot\authmain.php on line 4" error
<?
session_start();
if ($password && $userid)
{
// if the user has just tried to log in
$db_conn = mysql_connect("localhost", "php", "php");
mysql_select_db("test", $db_conn);
$query = "select * from login "
."where Name='$userid' "
." and Passwd='$password'";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $userid;
session_register("valid_user");
}
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br>";
echo "<a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo "Could not log you in";
}
else
{
// they have not tried to log in yet or have logged out
echo "You are not logged in.<br>";
}
// provide form to log in
echo "<form method=post action=\"authmain.php\">";
echo "<table>";
echo "<tr><td>Userid:</td>";
echo "<td><input type=text name=userid></td></tr>";
echo "<tr><td>Password:</td>";
echo "<td><input type=password name=password></td></tr>";
echo "<tr><td colspan=2 align=center>";
echo "<input type=submit value=\"Log in\"></td></tr>";
echo "</table></form>";
}
?>
</body>
</html>
I understand the page is processed for the firs time, $password is not initialized, but it never gave me such error on linux. Does anyone know how to get rid of this error?
thanks
<?
session_start();
if ($password && $userid)
{
// if the user has just tried to log in
$db_conn = mysql_connect("localhost", "php", "php");
mysql_select_db("test", $db_conn);
$query = "select * from login "
."where Name='$userid' "
." and Passwd='$password'";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $userid;
session_register("valid_user");
}
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br>";
echo "<a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo "Could not log you in";
}
else
{
// they have not tried to log in yet or have logged out
echo "You are not logged in.<br>";
}
// provide form to log in
echo "<form method=post action=\"authmain.php\">";
echo "<table>";
echo "<tr><td>Userid:</td>";
echo "<td><input type=text name=userid></td></tr>";
echo "<tr><td>Password:</td>";
echo "<td><input type=password name=password></td></tr>";
echo "<tr><td colspan=2 align=center>";
echo "<input type=submit value=\"Log in\"></td></tr>";
echo "</table></form>";
}
?>
</body>
</html>
I understand the page is processed for the firs time, $password is not initialized, but it never gave me such error on linux. Does anyone know how to get rid of this error?
thanks