Register and Login, mysql_result argument error

Post here is you are having problems with any of the tutorials.
Post Reply
TheChosenHalf
Posts: 4
Joined: Thu Feb 02, 2012 4:02 pm

Register and Login, mysql_result argument error

Post 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:
[syntax=php]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;
}[/syntax]

Help would be appreciated.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Register and Login, mysql_result argument error

Post by Temor »

You're using semi-quotes ( ' ) where you should be using backticks ( ` ).
This:
[syntax=php] $total = mysql_query("SELECT COUNT('user_id') FROM 'Accounts' WHERE 'user_name' = '{$user}'");[/syntax]
Should look like this:
[syntax=php] $total = mysql_query("SELECT COUNT(`user_id`) FROM `Accounts` WHERE `user_name` = '{$user}'");[/syntax]

For future reference, add [syntax=php]die(mysql_error());[/syntax] or [syntax=php]echo mysql_error();[/syntax] after the query that is failing and it will give you detailed instructions on what's causing the error.
TheChosenHalf
Posts: 4
Joined: Thu Feb 02, 2012 4:02 pm

Re: Register and Login, mysql_result argument error

Post by TheChosenHalf »

eh, still the same problem.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Register and Login, mysql_result argument error

Post by Temor »

is the table named Accounts?
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Register and Login, mysql_result argument error

Post by EcazS »

Did you actually put echo mysql_error(); after your query?
It should have given you different error.
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Register and Login, mysql_result argument error

Post by bowersbros »

post your new code :)
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
TheChosenHalf
Posts: 4
Joined: Thu Feb 02, 2012 4:02 pm

Re: Register and Login, mysql_result argument error

Post by TheChosenHalf »

yes, the name is Accounts

the mysql_error() did nothing... :s

and here is the new code:
[syntax=php]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();
}[/syntax]


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.
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Register and Login, mysql_result argument error

Post by bowersbros »

the reason it did nothing is because you did it too late.

Do it before the return.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
TheChosenHalf
Posts: 4
Joined: Thu Feb 02, 2012 4:02 pm

Re: Register and Login, mysql_result argument error

Post by TheChosenHalf »

i tied that too...

oh... wait it did throw an error, wrong db name -.-"
thanks for the help :D
Post Reply