Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:21:56+00:00 2026-06-14T20:21:56+00:00

If a user does not exist its supposed to throw back an error on

  • 0

If a user does not exist its supposed to throw back an error on the login screen but the user is then brought to the home page as if they have previously registered in my sign controller. The login controller – validate credentials function – and my model – function can_log_in() – will illustrate the error its supposed to bounce back

model:

  class Membership extends CI_Model
{
function Membership()
{
    parent::__construct();
}


public function can_log_in()
{
    $this->db->select('*')->from('membership');
    $this->db->where('username', $this->input->post ('username'));
    $this->db->where('password', md5($this->input->post ('password')));

    $query = $this->db->get('membership');
    if ($query->num_rows() == 1)
    {
        return true;
    }

    else{

        return false;

    }

}

login controller:

 class Login extends CI_Controller 
 {

   function Login()
    {
     parent::__construct();

      $this->load->model('membership');
    }


    function loguserin()

    {

$this->load->helper(array('form', 'url'));

$this->load->library('form_validation');

$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|trim');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');


$username = $this->input->post('username');
$password = $this->input->post('password');
      if ($this->form_validation->run()==TRUE)
     {
          $this->load->model('membership');
           if($this->membership->can_log_in($this->input->post('username'),$this->input->post('password'))
       { // this is unepected despite a new if statement called
        $this->session->set_userdata('status', 'OK');
        $this->session->set_userdata('username', $username);  
        redirect('home');
        } else //this else is unexpected
          {
       $this->session->set_userdata('status', 'NOT_OK');

      $this->session->set_flashdata('Incorrect username/password');
       $this->index();
      }
    } else {
   $this->index; 

   }

  }







        function logout()
      {
$this->session->sess_destroy();
redirect ('start');
       }


      function index()
      {
      $this->load->view('shared/header');
       $this->load->view('account/logintitle');
      $this->load->view('account/loginview');
        $this->load->view('shared/footer');
       }
      }

Once again thanks 🙂 its just that the user if not already in the table should not be able to sign into the home page

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:21:57+00:00Added an answer on June 14, 2026 at 8:21 pm

    Your logic is all over the place and you’re misunderstanding the concept of form validation. Form validation validates form input that’s it, it does not validate credentials. The validate_credentials function you have is sort of pointless to be honest since you can’t call the form validation error from outside the run function. So you may as well just make that go away entirely.

    First, the initial call after form_validation should be like this:

    if ($this->form_validation->run()==TRUE)
    {
        $this->load->model('membership');
        if($this->membership->can_log_in($this->input->post('username'),$this->input->post('password')))
        {
        $this->session->set_userdata('status', 'OK');
        $this->session->set_userdata('username', $username);  
        redirect('home');
        } else {
        $this->session->set_userdata('status', 'NOT_OK');// you'll need to do something
       // here to tell them their credentials are wrong as I said this won't work through
       // the form validation, perhaps look into using $this->session->set_flashdata()
        $this->index();
        }
    } else {
    $this->index; //reload the index to display the validation errors
    

    Okay that takes care of sending the data to the login function, now the function actually needs to receive data, and since it is NOT the first page sent the data the post string will be empty, that is why I passed the data in the function above. The only part of the model that should need to change is the following:

    public function can_log_in($username,$password)
    {
    $this->db->select('*')->from('membership');
    $this->db->where('username', $username);
    $this->db->where('password', md5($password));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When its giving an error saying AppHelper does not exist, am I missing any
if a user goes to URL: http://domain.com/folder/page.php?error=404 (which does not exist) How can I
customers does not want to allow user to use back or forward button. Just
I'm sending user data via jQuery to TCPDF, but it does not display any
The user does not want to receive the approval emails in Salesforce. Is there
I want to put validator so that if the user does not put the
I'm having a problem dropping a temporary table. The user account does not have
I need to add a user profile variable in java, apparently %userprofile% does not
I've done this before with inputs, why on earth does this not work? http://euroworker.no/user/checkout
How does the Authorize Tag determine if the user is authorized or not? Like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.