View Single Post
Old 02-06-2009, 10:15 PM   #2 (permalink)
trmbne2000
The Wanderer
 
Join Date: Nov 2007
Posts: 13
Thanks: 0
trmbne2000 is on a distinguished road
Default

The problem with your code is the if (count($errors)) { on line 4 of the login function. Your error array is $error earlier in the code.

I see that you are passing in the username and password arguments, yet you are still looking for the POST values in the function. It may be better to use:
Code:
function login($username, $password){
    $error = array();
    if (empty($username) || empty($password)) {
        echo 'A valid username and password is needed';
    } else {
        $conn = db_connect();
        $result = $conn->query("SELECT * FROM admin WHERE username='$username' AND password=sha1('$password')");
        if (!$result){
            die('Unable to connect to database at this time, please try again later.');
        }
    }
}
AND
Code:
  if (isset($_POST['username'])) {
    login($_POST['username'],$_POST['password']);
  }
Not sure if you only gave a partial example of your db_connect() method, but you may need to look at that as well (no reference to the db object is returned, so you may not be able to query it).

--Andrew
trmbne2000 is offline  
Reply With Quote