I didn't want to come here asking for help, I wanted to try for myself to sort it, but yeah... I've tried everything I can think of and am getting nowhere.
//--------------------
// Login Function
//--------------------
function login($username, $password, $remember) {
// Connect to the database
global $mysql;
// First we need to check that the user info submitted is correct!
// Errors will be sotred in an array, which will be stored in a variable
$errors = array();
// Query used throughout the function
$query = mysql_query("SELECT * FROM members WHERE username = '".$username."'") or die(mysql_error());
// Fetch info from query
$user = mysql_fetch_object($query);
// Username checking
if(empty($username)) {
$errors[] = "Username field left empty.";
}
else {
// Check if username exists
if(mysql_num_rows($query) == 0) {
$errors[] = "Username does not exist.";
}
}
// Password checking
if(empty($password)) {
$errors[] = "Password field left empty.";
}
else {
// Check if passwords match
if($password != $user->password) {
$errors[] = "Password is incorrect.";
}
}
// Check if user wants to remember their login
if($remember) {
setcookie('user_id', $user->id, time()+60*60*24*365, '/'); // Cookie set for 1 year
}
if($errors) {
return false;
}
else {
return true;
}
}
That' my login function that I wrote... it does the job, so I'm satisfied with it. Now as you can see, the errors are put into an array. Also to point out, I am using Smarty for my site, thought I'd give it a try, so far so good, though it appears that when I use $smarty->assign('blah', 'r0r'); I get an error: "Call to a member function assign() on a non-object" though that's no my issue.
I want to be able to grab the $errors variable with the errors in and put it in a Smarty assign function, but I can't seem to get a hold of the damn thing. The closest I came was:
if($errors) {
print_r($errors);
}
else {
return true;
}
So my question really, is how can I get the $errors variable to work outside of the function?
Sorry if I'm not making sense, when it comes to TALKING about code, I'm not so bright.
Thanks for looking.
- Chris.
Edited by .CJ, 22 August 2007 - 05:05 PM.
