Similar to the challenge discussed above I get the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/serve/fun4nick/PHP/chapter20/authmain.php on line 14
When I run:
<?
session_start();
if ($userid && $password)
{
// if the user has just tried to log in
$db_conn = mysql_connect( 'mysql.serve.com', 'username', 'userpw' );
mysql_select_db( 'auth' , $db_conn);
$query = "select * from auth "
."where name='$userid' "
." and pass=password('$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>";
}
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>
This is row 14 if (mysql_num_rows($result) >0 )
Can you see why I am getting this error?
Thanks for your help....