Jump to content

problems checking account activation status in login script from database!


barbs75

Recommended Posts

Hey guys,

 

I am trying to add the email activation script to my login system, but it doesnt seem to be working....

 

i have added the following code to check the status:

 

else {
//check that user has activated their account
$sql_status_check = "SELECT * FROM customer WHERE username='$user'";
$status_check_result = mysql_fetch_array(mysql_query($sql_status_check));
$status_info = $status_check_result['status'];
//if account hasnt been activated, throw error
if ($status_info > 0) {
	$error = "You haven't yet fully activated your account. Please check your email inbox";
} 

 

Does that look correct?? is there anything i am missing?

 

The full code of the whole page is shown below, in case i have missed out anything elsewhere in the script

 

<?php 
session_start(); 
header("Cache-control: private"); 
$user = $_POST['username']; 
$pass = $_POST['password'];

$con = mysql_connect("localhost","root","12waldron"); //Replace with your actual MySQL DB Username and Password
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("customerhouses_db", $con); //Replace with your MySQL DB Name //change to database connection file

// checking if the user exists 
$sql_user_check = "SELECT * FROM customer WHERE username='$user'"; //your table name here
$result_name_check = mysql_query($sql_user_check); 
$usersfound = mysql_num_rows($result_name_check); 
// if user not found, note that and end 
if ($usersfound < 1) { 
    $error = "User $user not found."; 
// if user does exist, continue with processing 
} else { 
    // checking if passwords match 
    $sql_pass_get = "SELECT * FROM customer WHERE username='$user'"; //your table name here
    $user_info = mysql_fetch_array(mysql_query($sql_pass_get)); 
    $encryptpass = $user_info['encryptpass']; 
    // if doesn't match, note that and end 
    if ($encryptpass != md5($pass)) { 
        $error = "Invalid password.  Try again.";
} else {
//check that user has activated their account
$sql_status_check = "SELECT * FROM customer WHERE username='$user'";
$status_check_result = mysql_fetch_array(mysql_query($sql_status_check));
$status_info = $status_check_result['status'];
//if account hasnt been activated, throw error
if ($status_info > 0) {
	$error = "You haven't yet fully activated your account. Please check your email inbox";
} else {
//create sessions for each table entry 
$_SESSION['username'] = $user_info['username'];
$_SESSION['title'] = $user_info['title'];
$_SESSION['forename'] = $user_info['forename'];
$_SESSION['surname'] = $user_info['surname'];
$_SESSION['email'] = $user_info['email']; 
$_SESSION['encryptpass'] = $user_info['encryptpass']; 
$_SESSION['membership'] = $user_info['membership']; 
} 
}
//checks username session is registered, if it isn't checks if a value is assigned to error, if it has been
//output error and send them back to login screen, otherwise they are logged in correctly and welcome them
if (!$_SESSION['username']) { 
    if ($error) { 
        echo $error; 
    } else { 
        include("welcome.php"); 
    }
//otehrwise they are still logged in and welcome them back! 
} else { 
    echo "<html><head><title>Welcome Back</title></head><body>Welcome back ".$_SESSION['username']."  <a href=\"settings.php\">Click here</a> to view your current settings.</body></html>"; 
}  
?>

 

cheers

 

Craig

Link to comment
Share on other sites

hey smithmr8,

 

Tried what you suggested, didnt help im afraid  :( do you know anything else that might be wrong??

 

When i execute the login.php script from login_form.html, a white screen appears, so its not executing any of the code by the looks of things

 

cheers

 

Craig

Link to comment
Share on other sites

hey,

 

no i didnt change it for all of the instances, i added the code for the status check to my login.php script, the script was working fine until i tried adding this script, so i dont see what the problem is....

 

My technique isnt wrong or anything is it??

 

cheers

 

Craig

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.