Page 1 of 1

Trouble with mysql_result!

Posted: Sat May 09, 2009 4:17 pm
by lase
Okay, I've been working on this for the last 3 hours. :banghead:

I don't know what I'm doing wrong, I'm getting this error when the script is run:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/lasegon/public_html/youscrape/authlib.php on line 64

Here's my sql query along with the code:

Code: Select all

$res =    mysql_query("SELECT password FROM users WHERE username =  '".$uname."'");
            //$resEncrypted = crypt($res,'SHA_512');
            $passEncrypted = crypt($pword, 'whirlpool');
            $row = mysql_result($res, 0);
$pword refers to a $_POST variable. $uname refers to a post variable.

If anyone could tell me whats wrong, thank you SO much.

Re: Trouble with mysql_result!

Posted: Sat May 09, 2009 5:02 pm
by califdon
Do yourself a huge favor, so you won't bang your head against the wall for 3 hours again: always make your queries like this:

Code: Select all

$sql="SELECT password FROM users WHERE username = '$uname'";
echo $sql;  // this is for debug, remove this line after it's working
$res=mysql_query($sql) or die(mysql_error());
 
It will tell you what the problem is immediately.

I hope you are sanitizing your POST variables before feeding them to the database!

Re: Trouble with mysql_result!

Posted: Sat May 09, 2009 5:39 pm
by lase
Califdon, thank you so^1000 much. I made a very stupid mistake that I seemed to have missed. I forgot to select the database XD. And yes, I have them going through escape stuff, and encryption stuffs before.

Re: Trouble with mysql_result!

Posted: Sat May 09, 2009 6:18 pm
by califdon
lase wrote:Califdon, thank you so^1000 much. I made a very stupid mistake that I seemed to have missed. I forgot to select the database XD. And yes, I have them going through escape stuff, and encryption stuffs before.
I'm sure lucky that I never make stupid mistakes . . . hey, that's what error messages are for. Let 'em work for you! Maybe the biggest stupid mistake I made was thinking that it would be fun to be a programmer! :P