Re: Functions are driving me crazy....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Pruim wrote:
Hi everyone :)

So partly to get an answer, and partly to boost my post rankings for the week I have a question.

I am attempting to write an authentication function which would query a database, check the username/password and return true if it matches. If it doesn't match, then it shouldn't return anything and they are denied access.

Here is the code for the function:

<?PHP
function authentication(){ if($user && $pass) { // Keep in mind, PASSWORD has meaning in MySQL
            // Do your string sanitizing here
            // (e.g. - $user = mysql_real_escape_string($_POST['user']);)
$loginQuery = "SELECT * FROM login WHERE user='".$user."' AND Userpass='".$pass."' LIMIT 0,1;"; $loginResult = mysql_query($loginQuery) or die("Wrong data supplied or database error" .mysql_error());
            while($row1 = mysql_fetch_array($loginResult)) {
                $_SESSION['user'] = $row1['User'];
                $_SESSION['loggedin'] = "YES";
                $authenticated = "true";
            }
        }
    }return $authenticated;
?>
Change:

}return $authenticated;

to

   return $authenticated;
}

else it will never return the value from the function. But it will always give you undefined variable notice

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux