Page 1 of 1

No results being returned from database?

Posted: Fri Jan 16, 2009 4:41 pm
by clodagh2000
Hi,
I have a problem with trying to pull information from the database. Its to confirm that a persons username and password are in the database. If they are, it will bring them to a login area, if they are not it will redirect them to the login page. However it is returning the message saying 'wrong info'. However the username and password are in the database. I cannot figure out where I have gone wrong. Any help would be much appreciated.

Code: Select all

$password = $_POST['password'];
$username = $_POST['username'];
 
//function to login to database
in();
        
                
        if ($db_found) 
        {
            $sql = "SELECT * FROM people WHERE username = '$username' AND password = '$password'";
            $result = mysql_query($sql);
            if ($result)
            {
                if (mysql_num_rows($result)>0)
                {
                    //yes they are the correct person
                    $_SESSION['user_id'] = mysql_result($result,0,"people_id");
                    mysql_close();
                    echo "session_set";
                    exit();
                    //redirect("main.php");
                } 
                else 
                {
                    // no they have incorrect detail
                    echo "wrong info";
                    mysql_close();
                    exit();
                    //redirect("login.php");
                
                }
            }
                       else
            {
                echo 'no results found';
            }
        }
        else 
        {
            echo "database problem!";
        }
        //function to log out of database   
        out();
 
?>

Re: No results being returned from database?

Posted: Fri Jan 16, 2009 4:44 pm
by Burrito
try:

Code: Select all

 
if($row = mysql_fetch_assoc($result))