Question: Can anyone please help me with the following error. I am making a register and login function for my website. I have it connected to my local database and in there I have created a user. When I test that I can login and that username and password is recognised, it works as expected. But I get this error

```
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 17 in C:\xampp\htdocs\LoginAndRegistration\core\functions\users.php on line 34

```

And this is what I have on line 34

```
return (mysql_result(mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"), 0) == 1) ? true : false;

```

Which is part of the following function

```
function login($username, $password) {
    $user_id = user_id_from_username($username);

    $username = sanitize($username);
    $password = md5($password);

    return (mysql_result(mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"), 0) == 1) ? true : false;
}

```

Ive been staring at it for ages now but cant seem to figure out the problem. Can anyone tell me what I am doing wrong?
Thanks

Answer: 
This error means the query failed. Always check if the query succeeded:

```
$q = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
if ($q) {
    if ($rows = mysql_num_rows($q)) {
        // Continue operation, or set a flag
    } else {
        // No matching rows, throw an Exception or set a flag
    }
} else {
    // Something is wrong
    die(mysql_error());
}

```
You are getting a warning (not an error) because **mysql\_query** at some times, it won't return any rows, so trying to get the first row with **mysql\_result** when there are not rows, will raise the warning.

You can try:

```
function login($username, $password) {
    $user_id = user_id_from_username($username);

    $username = sanitize($username);
    $password = md5($password);

    $query = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
    if (mysql_num_rows($query) > 0)
        return true;
    else
        return false;
}

```