can't figure out the error

I am new to PHP and I have been following a tutorial on how to build a login and registration form. Can someone help me figure out what is wrong with this line of code.

function user_active($username) {
$username = sanitize($username);
return (mysql_result(mysql_query(“SELECT * FROM user WHERE username =’$username’ AND active = 1”), 0) == 1) ? true : false;
}

This is the error I am getting: ( I am using dreamweaver)

( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 15 in C:\wamp\www\Template\core\functions\users.php on line 31
Call Stack

Time Memory Function Location

1 0.0020 261736 {main}( ) …\register.php:0
2 0.0250 295280 user_exists( ) …\register.php:30
3 0.0256 298680 mysql_result ( ) …\users.php:31

I am clearly not decent enough to trace the pathing error so any suggestions would be awesome.

Are you starting from scratch? If so, I would recommend learning to use either PDO or mysqli

As far as your error goes, I’m guessing that mysql_query is either returning an error or no results.

It is returning an error in my registration form (properly). I just wasn’t sure if my code was broken. I was reading something about the PDO and mysqli, but I wasn’t sure how I could implement that change and still keep with this tutorial I am following. Any suggestions?

If you execute the query manually does it return any results? You are executing mysql_result without knowing if there are any results. If the query returns zero the mysql_result function will always fail.

Here is a good tutorial to learn PDO

thanks it seems to be working fine I just have it showing errors so it shows that there is an error when there isn’t. Or at least that is what I am assuming. Thanks for the tutorial i will check it out.

Sponsor our Newsletter | Privacy Policy | Terms of Service