mysql query fail
Posted: Fri Apr 20, 2007 8:46 pm
I have a database of users. When I try to authenticate users to see if they have provided the correct password I am always thrown an error. I thought the problem was that username and password fields were varchar datatypes in my table, but not so, it still get thrown an error that the result of the query is invalid.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/workspace/notes/login.php on line 20
Anyone have a clue as to whats up?
Code: Select all
$dbh = mysql_connect ("localhost", $user, $password);
mysql_select_db ($db);
if ($_POST['btnlogin']) {
$username = $_POST['username'];
$password = $_POST['password'];
$sqlusers = "SELECT * FROM users WHERE username = $username";
$result = mysql_query($sqlusers) or mysql_error(); //this doesnt ever seem to be a valid mysql resource.
if (!mysql_num_rows($result) or mysql_error()) { // this is line 20
echo 'There are no users registered.';
die();
}
$userinfo = mysql_fetch_assoc($result);
echo 'Thank you for logging in ' . $userinfo['username'];Anyone have a clue as to whats up?