Welcome Guest, Not a member yet? Register   Sign In
Model (verify username & password
#11

[eluser]psychoder[/eluser]
can you post your view for log in (your log in form)

Code:
function login()    {
        
                $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Username','required|xss_clean|trim');
        $this->form_validation->set_rules('password', 'Password','required|xss_clean|trim');
        
        
        
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('loginview');
        }
        else {
                $this->load->model("model_name");
                $username = $this->input->post("username");
                $password = $this->input->post("password");
                if($this->model_name->check_login($username,$password))
                echo ' YOUR IN!!!';
                else
                echo 'invalid combination';

        }
    
    }

add this one

Code:
$username = $this->input->post("username");
$password = $this->input->post("password");
#12

[eluser]terry101[/eluser]
i realized that i dont have a table name anywhere. usually when doing a SQL query the name would be in that SELECT * FROM "table name". but the short cut i took iam confused on how to or where to add in tables.
#13

[eluser]terry101[/eluser]
ok so i added the input part, and now my controller looks like this


Controller
Code:
function login()    {
        
                $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Username','required|xss_clean|trim');
        $this->form_validation->set_rules('password', 'Password','required|xss_clean|trim');
        
        
        if ($this->form_validation->run() == FALSE) {
            
            $this->load->view('loginview');
        }
        else {
        
                $this->load->model('loginmodel');
                 $username = $this->input->post('username');
         $password = $this->input->post('password');
                if ($this->loginmodel->check_login($username, $password)){
                    
            echo 'your in';
                    }
            
            else {
                
                echo 'username or password was invalid; try again';
            
            }            
        }
    
    }
}


My view is below (its a little dirty and i do plan on changing the method of my view(for testing purposes i'll just keep it like this for now)

Code:
<html>
    <title> Login </title>

<h3> Please Login In</h3>

<div id= "login_form">
    

    &lt;?php echo form_open($base_url . 'userlogin/login');?&gt;
    <ul>
        <li>
            <lable>Username</label>
            <div>
                &lt;?php echo form_input(array('id' => 'username', 'name' => 'username'));?&gt;    
            </div>
        </li>        
        
        <li>
            <lable>Password</label>
            <div>
                &lt;?php echo form_password(array('id' => 'password', 'name' => 'password'));?&gt;    
            </div>
        </li>
        
        <li>
        &lt;?php echo form_submit(array('name' =>'submit'), 'login');?&gt;    
        </li>
        
        <li>
            &lt;?php echo validation_errors();?&gt;    
        </li>
    </ul>
    
    
    &lt;?php echo form_close();?&gt;
</div>


&lt;/html&gt;
#14

[eluser]terry101[/eluser]
ok i messed up when inserting the table in the get_where function i added in the table but i still get a error on the same line as before.

error line
Code:
if ($verifylogin->num_row()== 1) {

MODEL
Code:
&lt;?php

class Loginmodel extends CI_Model {
    
    function check_login ($username, $password) {
        $en_password = MD5($password);
        
        $this->load->database('blog');
        
        $checklogin = array('username' => $username, 'password' => $en_password);
        $verifylogin = $this->db->get_where('tbregister',$checklogin);
    
        if ($verifylogin->num_row()== 1) {
            
            return TRUE;
        }
        else {
            
            return FALSE;
        }
    }
}
#15

[eluser]CodeIgniteMe[/eluser]
You have to set the table name in the get() method:
Code:
$data = array('username'=>$username,'password'=>$password);
$myresult = $this->db->where($data)->get('tablename');
return $myresult->result();

I have edited my recent post because I found out that doesn't work inside [code] tags. It was supposed to be for highlighting.
#16

[eluser]CodeIgniteMe[/eluser]
Check your queries. Maybe there's a name conflict in your table or columns.
#17

[eluser]psychoder[/eluser]
does it work now?
#18

[eluser]terry101[/eluser]
nah, field seem to be fine.

I tried this as well and no dice
Code:
$myresult = $this->db->where($data)->get('tablename');
but quick question about this; is the code above the same as the one below?both are the same function correct?
Code:
$verifylogin = $this->db->get_where('tbregister',$checklogin);

I still get the same error on the same line as before even if i tried both the lines above

error line
Code:
if ($verifylogin->num_row()== 1) {
#19

[eluser]CodeIgniteMe[/eluser]
they are both the same, in fact, if you browse inside the source codes, you will see that they are just referring to each other. get_where() is just an alias of the where() and get() functions combined together.

for debugging your problem, you can use var_dump() on $verify_login before you check for num_rows()
Code:
$verifylogin = $this->db->get_where('tbregister',$checklogin);
var_dump($verifylogin);
#20

[eluser]terry101[/eluser]
ok i did what you mentioned and i got this error. thats my result when debugging. mad confused tho. any idea?

object(CI_DB_mysql_result)[17]
public 'conn_id' => resource(29, mysql link persistent)
public 'result_id' => resource(34, mysql result)
public 'result_array' =>
array
empty
public 'result_object' =>
array
empty
public 'custom_result_object' =>
array
empty
public 'current_row' => int 0
public 'num_rows' => int 0
public 'row_data' => nul




Theme © iAndrew 2016 - Forum software by © MyBB