Sarwar Alam
Sarwar Alam

Reputation: 93

mysql_result SHOWING SYNTAX ERROR

I am working with login system and having a error while using

mysql_result() function

The error is:

Parse error: syntax error, unexpected ','

Here is the code

function user_exists($username){
    $username = sanitize($username);
    $query = mysql_query("SELECT COUNT(`user_id`) FROM `p32_users` WHERE `user_name` = '$username'");
    return (mysql_result(($query , 0) == 1) ? true : false;
}

Thank you

Upvotes: 0

Views: 51

Answers (2)

Peter
Peter

Reputation: 9123

The following query should fix your problem:

$query = mysql_query("SELECT
COUNT(user_id)
FROM p32_users
WHERE user_name='{$username}'
");

return (mysql_result($query, 0) == 1) ? true: false;

Upvotes: 0

Barmar
Barmar

Reputation: 781380

Your parentheses are messed up. It should be

return (mysql_result($query, 0) == 1) ? true: false;

Furthermore, there's no need for the ternary expression, since == returns true or false by itself. So just:

return mysql_result($query, 0) == 1;

Upvotes: 4

Related Questions