Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
Hello everyone I hope you could help with this problem like you did with my last one. I'm trying to make a user registration with php and I do everything good except this:
Warning: mysql_result(): supplied argument is not a valid
MySQL result resource in
First I've tried to do a sanitize function but it didn't work. Here is my first try
function user_exists ($username){
$username = sanitize ($username);
return (mysql_result(mysql_query("SELECT COUNT('id') FROM 'members' WHERE
'username' = '$username' "), 0) == 1) ? true : false;
}
Then I though I could try with the mysql_real_escape_string but then that mysql_result error came and it is driving me crazy because I can't find what I got wrong. Here is my code with the mysql_real_escape_string:
function user_exists ($username){
$username = mysql_real_escape_string ($username);
return (mysql_result(mysql_query("SELECT COUNT('id') FROM 'members' WHERE
'username' = '$username' "), 0) == 1) ? true : false;
}
I hope someone could tell me where I got it wrong so I could learn from my mistakes. Thank you all!!!
problem is you are wrapping table name and column names with single quote, it must be removed since the names are not on MySQL Reserved Keyword List and the proper way to escape it is by using backticks.
SELECT COUNT(id)
FROM members
WHERE username = '$username'