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.
Register and Login, mysql_result argument error
-
- Posts: 4
- Joined: Thu Feb 02, 2012 4:02 pm
Re: Register and Login, mysql_result argument error
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.
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.
-
- Posts: 4
- Joined: Thu Feb 02, 2012 4:02 pm
Re: Register and Login, mysql_result argument error
eh, still the same problem.
Re: Register and Login, mysql_result argument error
is the table named Accounts?
Re: Register and Login, mysql_result argument error
Did you actually put echo mysql_error(); after your query?
It should have given you different error.
It should have given you different error.
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Register and Login, mysql_result argument error
post your new code ![Smile :)](./images/smilies/icon_e_smile.gif)
![Smile :)](./images/smilies/icon_e_smile.gif)
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ![Wink ;)](./images/smilies/icon_e_wink.gif)
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
![Wink ;)](./images/smilies/icon_e_wink.gif)
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
-
- Posts: 4
- Joined: Thu Feb 02, 2012 4:02 pm
Re: Register and Login, mysql_result argument error
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.
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.
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Register and Login, mysql_result argument error
the reason it did nothing is because you did it too late.
Do it before the return.
Do it before the return.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ![Wink ;)](./images/smilies/icon_e_wink.gif)
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
![Wink ;)](./images/smilies/icon_e_wink.gif)
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
-
- Posts: 4
- Joined: Thu Feb 02, 2012 4:02 pm
Re: Register and Login, mysql_result argument error
i tied that too...
oh... wait it did throw an error, wrong db name -.-"
thanks for the help![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
oh... wait it did throw an error, wrong db name -.-"
thanks for the help
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)