Welcome Guest, Not a member yet? Register   Sign In
Login Error
#1

[eluser]GamingFusion[/eluser]
I am creating a site that has a simple login/logout functionality.

I am getting this error after submitting the form
Quote:Fatal error: Cannot use object of type CI_DB_mysql_result as array in *Censored*/system/application/models/members.php on line 18

Heres my form

Code:
<?php
    if (isset($logged_in) == true) {
        if ($logged_in == TRUE)
        {
             redirect('/social/', 'refresh');
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;SocialCrab | Login&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?=base_url()?&gt;assets/css/login.css" media="screen" /&gt;
&lt;/head&gt;

&lt;body&gt;

<div class="container">
    <div class="header">
        <img src="&lt;?=base_url();?&gt;assets/images/logo.png" alt="Logo" />
    </div>
    
    <div class="content">
        &lt;?php
            $nowTime = '%h:%i %a';
            $nowDay = '%d';
            $nowMonth = '%m';
            $time = time();
            $errors = validation_errors();
            
            if ($errors) {
                echo '<div class="error">';
                echo validation_errors();
                   echo '</div>';
            }
        ?&gt;
        
        <center><h2>Login</h2></center>
        &lt;?=form_open('login/validate')?&gt;
        &lt;?=form_hidden('time', mdate($nowTime, $time))?&gt;
        &lt;?=form_hidden('day', mdate($nowDay, $time))?&gt;
        &lt;?=form_hidden('month', mdate($nowMonth, $time))?&gt;
        <table>
            <tr><td>Email: </td><td>&lt;?=form_input('email', set_value('email'))?&gt;</td></tr>
            <tr><td>Password:</td><td>&lt;?=form_password('password')?&gt;</td></tr>
            <tr><td>&lt;?=form_submit('submit', 'Login')?&gt;</td></tr>
        </table>
    </div>
    
    <div class="footer">
            Copyright 2010 SocialCrab
    </div>
</div>

&lt;/body&gt;
&lt;/html&gt;

and heres my controller for that view file

Code:
&lt;?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('date');
    }
    
    function index()
    {
        $data['logged_in'] = false;
        $this->load->view('socialcrab/login/index', $data);
    }
    
    function validate()
    {
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|sha1');
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('socialcrab/login/index');
        }
        else
        {            
            $this->load->model('members');

            if ($this->members->login() == FALSE)
            {
                
            }
        }    
    }
}
?&gt;

and heres login function from my model(the "*" shows line 19)

Code:
function login()
    {
        $email = $this->input->post('email');
        $password = $this->input->post('password');
        
        $logged = $this->db->get_where('users', array ('email' => $email, 'password' => $password));
        
        if ($logged) {
*            $uId = $logged['id'];
            $uFirst = $logged['first'];
            $uLast = $logged['last'];
        }else{
            echo 'No User';    
        }
        
        if ($uName) {
            return TRUE;
        }else{
            return FALSE;
        }
    }

whats wrong?

*EDIT* I have also just noticed that i get the same error no matter what email i enter. even the correct one. is is it not checking the database properly?
#2

[eluser]WanWizard[/eluser]
$this->db->get... returns an active record object, not an array.
Code:
$query = $this->db->get_where('users', array ('email' => $email, 'password' => $password));
        
if ( $query->num_rows() == 1 ) {
    $logged = $query->row_array();
    $uId = $logged['id'];
    $uFirst = $logged['first'];
    $uLast = $logged['last'];
}
else
{
    echo 'No User';    
}
#3

[eluser]GamingFusion[/eluser]
ok thanks man




Theme © iAndrew 2016 - Forum software by © MyBB