[FONT="Courier New"]<?php
$username = $POST['username'];
$password = $POST['password'];
$self = $SERVER['PHP_SELF'];
$referer = $SERVER['HTTP_REFERER'];
if either form field is empty return to the log-in page
if( ( !$username ) or ( !$password ) )
{ header( "Location:$referer" ); exit(); }
#connect to MySQL
$conn=@mysql_connect( "localhost", "root", "rootpassword" )
or die( "Could not connect" );
#select the specified database
$rs = @mysql_select_db( "user_test", $conn )
or die( "Could not select database" );
#create the query
$sql = "select * from users where user_name=\"$username\" and password=password( \"$password\" )";
#execute the query
$rs = mysql_query( $sql, $conn )
or die( "Could not execute query" );
#get number of rows that match username and password
$num = mysql_num_rows($rs)
or die( "number of rows query failed");
#if there is a match the log-in is authenticated
if( $num != 0 )
{
$msg = "<h3>Welcome $username - your log-in succeeded!</h3>";
}
else
{
$msg = "no match found";
}
?>
<html>
<head>
<title>Log-In Authenticated</title>
</head>
<body>
<?php echo( $msg ); ?>
</body>
</html>[/FONT]
This code dies at the "$num = mysql_num_rows($rs)" row even though my hostname is correct, my mysql-username is correct and my mysql-password is correct and all the variables and text boxes on the previous page are all correctly named
interestingly enoughin this line:
"[FONT="Courier New"]$sql = "select * from users where user_name=\"$username\" and password=password( \"$password\" )";[/FONT]"
if i remove the password cirteria so it's only looking for username, it all works.
I'm incredibly confused because this is an example from a book "PHP5 in easy steps" by Mike McGrath and I've named my database and copied the code exactly (but fixing his typo that sed "[FONT="Courier New"]mysql_numrows[/FONT]" instead of "[FONT="Courier New"]mysql_num_rows[/FONT]") and it simply refuses to work