I have customised 2 tutorials into 1 for my website. I am just needing a little help with a little more custom code I want to add.
When users register their account, it goes into the database as “unactivated”. Later they can activate it through another script I have. The part I need a little help with is that at the login page I want it to give an error when the account is still not activated.
I have tried for a few days to get it to work, but I am still quite new to PHP and just haven’t been able to crack it by myself.
So if anyone is willing to help, here are the details. Firstly… the login code…
[php]// Reset errors and success messages
$errors = array();
$success = array();
// Login attempt
if(isset($_POST[‘loginSubmit’]) && $_POST[‘loginSubmit’] == ‘true’){
$loginEmail = trim($_POST[‘email’]);
$loginPassword = trim($_POST[‘password’]);
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $loginEmail))
$errors['loginEmail'] = 'Error: Please enter a valid email address.';
if(strlen($loginPassword) < 6 || strlen($loginPassword) > 12)
$errors['loginPassword'] = 'Error: Your password must be between 6-12 characters.';
if(!$errors){
$query = 'SELECT * FROM users WHERE email = "' . mysql_real_escape_string($loginEmail) . '" AND password = MD5("' . $loginPassword . '") LIMIT 1';
$result = mysql_query($query);
if(mysql_num_rows($result) == 1){
$user = mysql_fetch_assoc($result);
$query = 'UPDATE users SET session_id = "' . session_id() . '" WHERE id = ' . $user['id'] . ' LIMIT 1';
mysql_query($query);
header('Location: index.php');
exit;
}else{
$errors['login'] = 'Error: Invalid email address/password combination.';
}
}
}[/php]
I would appreciate it if you could show me in the right direction to check the database to find out if the user is activated or not, and also add a new error, “Account Innactive” or something similar in the same way as it is already done for the other errors.
Thanks to anyone who can help