Can somebody tell me what I'm doing wrong?? I keep getting Could not log you in. I know I'm connecting to the db and when I do the query on my server, it works. I have echo'ed the query result and get "resource id #3". what does that mean? I'm sure it is something stupid...
Thanks for any help in this!
<script language="php">
session_start();
if ($userid && $password)
{
// if the user has just tried to log in
$db_conn = mysql_connect("localhost", "localhost", "pswd") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("dbname", $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");
}
}
</script>
//in the body of the html...
<script language="php">
if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br>";
echo "<a href=\"logout.htm\">Log out</a><br>";
}
else
{
if (isset($userid))
{
// tried and failed to log in
echo "Could not log you in";
echo $userid;
}
else
{
// 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=\"auth.htm\">";
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>";
}
</script>