No results being returned from database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clodagh2000
Forum Newbie
Posts: 4
Joined: Fri Aug 10, 2007 9:46 am

No results being returned from database?

Post 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();
 
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: No results being returned from database?

Post by Burrito »

try:

Code: Select all

 
if($row = mysql_fetch_assoc($result))
 
Post Reply