0
votes

Ive got a Codeigniter login system here, and just wondering where im going wrong. Heres my code:

View

<?php
echo form_open('handyman/logIn');
echo form_label('Email: ','useremail');
echo form_input('useremail');
echo "<br />";
echo form_label('Password: ','userpassword');
echo form_input('userpassword');
echo "<br />";
echo form_submit('Logmein','Log In');
echo form_close();
?>

Controller

public function logIn(){
      $useremail=$this->input->post('useremail');
      $userpassword=md5($this->input->post('userpassword'));
      $this->load->model("HandymanModel");

      if($useremail && $userpassword && $this->HandymanModel->logInUser($useremail,$userpassword)){
        $data['msg']="Successfully Logged in!";
        $data['title']="Logged In";
        $this->load->view("header",$data);
        $this->load->view("confirmation",$data);
        $this->load->view("footer",$data);
      } else{
        $data['title']="Sign up / Log in";
        $this->load->view("header",$data);
        $this->load->view("page3", $data);
        $this->load->view("footer",$data);
      }
    }

Model

 function logInUser($useremail,$userpassword) { 
    $this->db->where('email',$useremail );
    $this->db->where( 'password', $userpassword );

    $login = $this->db->get()->result();

    if (is_array($login) && count($login) == 1) {
        return true;
    } else {
        return false;
    } 

I'm getting Error Number: 1064 which is check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE email = '[email protected]' AND password = '1a1dc91c9073' at line 2

Thanks

2
This doesn't answer your question, but see stackoverflow.com/questions/7044785/…. You shouldn't be using md5 for your passwords. - Mike
I invite you to use $login = $this->db->get()->num_rows(); instead. It works better for your purpose - Kalzem
@Mike I know you shouldn't use MD5 but its for a university project so it doesn't really matter! - Awilson089
@Awilson089 impress your professor! - Mike

2 Answers

3
votes

You re missing the table name

$login = $this->db->get( )->result();
                        ^^here

Try this by adding table name

$login = $this->db->get('your table name')->result();

$this->db->get();

1
votes

I would change your model to something like...

function logInUser($useremail,$userpassword) {

$query = $this->db->query('SELECT * FROM tbl_name WHERE account_email="'.$useremail.'" AND account_password = "'.$userpassword.'"');

if ($query->num_rows() != 0){
    return true;
} else {
    return false;
} 

}

I would also suggest encrypting user passwords as well. take a look at MD5. Make sure you use a hash as well.

Cheers!