Page 1 of 1
Register and Login, mysql_result argument error
Posted: Thu Feb 02, 2012 4:10 pm
by TheChosenHalf
Hi,
I'm having trouble with the Register an Login tutorial part 4(actualy the error is in user.inc.php), when I try to register with empty fields I get an error(I've been trying to solve it for an hour):
Warning: mysql_result(): supplied argument is not a valid MySQL result resource
code:
function user_exists($user){
$user = mysql_real_escape_string($user);
$total = mysql_query("SELECT COUNT('user_id') FROM 'Accounts' WHERE 'user_name' = '{$user}'");
return (mysql_result($total, 0) == '1') ? true : false;
}
Help would be appreciated.
Re: Register and Login, mysql_result argument error
Posted: Thu Feb 02, 2012 5:55 pm
by Temor
You're using semi-quotes ( ' ) where you should be using backticks ( ` ).
This:
$total = mysql_query("SELECT COUNT('user_id') FROM 'Accounts' WHERE 'user_name' = '{$user}'");
Should look like this:
$total = mysql_query("SELECT COUNT(`user_id`) FROM `Accounts` WHERE `user_name` = '{$user}'");
For future reference, add
die(mysql_error());
or
echo mysql_error();
after the query that is failing and it will give you detailed instructions on what's causing the error.
Re: Register and Login, mysql_result argument error
Posted: Fri Feb 03, 2012 3:36 pm
by TheChosenHalf
eh, still the same problem.
Re: Register and Login, mysql_result argument error
Posted: Fri Feb 03, 2012 5:52 pm
by Temor
is the table named Accounts?
Re: Register and Login, mysql_result argument error
Posted: Fri Feb 03, 2012 11:35 pm
by EcazS
Did you actually put echo mysql_error(); after your query?
It should have given you different error.
Re: Register and Login, mysql_result argument error
Posted: Fri Feb 03, 2012 11:47 pm
by bowersbros
post your new code
Re: Register and Login, mysql_result argument error
Posted: Sat Feb 04, 2012 10:22 am
by TheChosenHalf
yes, the name is Accounts
the mysql_error() did nothing... :s
and here is the new code:
function user_exists($user){
$user = mysql_real_escape_string($user);
$total = mysql_query("SELECT COUNT(`user_id`) FROM `Accounts` WHERE `user_name` = '{$user}'");
return (mysql_result($total, 0) == '1') ? true : false;
echo mysql_error();
}
edit: You can check yourself:
http://www.cevapinpol.comlu.com/
Go to testing area 1 and try to register with no info inputed... It doesnt register even if you enter info anyway because it uses the same function.
Re: Register and Login, mysql_result argument error
Posted: Sat Feb 04, 2012 10:37 am
by bowersbros
the reason it did nothing is because you did it too late.
Do it before the return.
Re: Register and Login, mysql_result argument error
Posted: Sat Feb 04, 2012 12:03 pm
by TheChosenHalf
i tied that too...
oh... wait it did throw an error, wrong db name -.-"
thanks for the help