Forum Moderators: coopster
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/export/www/hosting/dkicks/admin/new_files/ses/index.php on line 27
here's part of my code (line 27 and such around it):
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username='$username' AND password= $password' LIMIT 1";
$result = mysql_query($query);
$check = mysql_num_rows($result);if ($check!=1) {
$error = "<font color=\"red\" size=\"+1\">Login failed.</font>";
print $error;
}else if ($check == 1){
session_start();
$_SESSION['username'] = $username;header("Location: admin.php");
}
any ideas whats wrong?
electricocean
$query = "SELECT * FROM users WHERE username='$username' AND password= $password' LIMIT 1";
You have omitted a single quote at $password. See if this corrects the error:
$query = "SELECT * FROM users WHERE username='$username' AND password= '$password' LIMIT 1";
Any time you see the error, supplied argument is not a valid MySQL result resource, look to your query first. I've only seen that error on malformed query statements.
$check = mysql_num_rows($result);
1 is simply the value being tested in the variable $check. Ideally, the value of $check will be 1 and only 1, since only 1 row should be returned from the query. But... more than 1 row could be returned and the value of $check will indicate how many rows were actually returned. The code is validating that only one row was returned from the query before allowing any further action.