Nidheesh N Namboodhiri
Nidheesh N Namboodhiri

Reputation: 199

Data retrieving is not working

In my codeigniter project, when the login button is clicked, it's not redirecting to the user home page. But for my client, it is working well.

When I use the print_r($query) it displays the following error:

CI_DB_mysql_result Object ( [conn_id] => Resource id #32 [result_id] => Resource id #38 > [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 0 [row_data] => )

I have tried result() at the end of my code, but it's still its not working. How do I solve this issue?

My Controller Code is as follows:

<?php 
class Main extends Controller {
   function Main()
   {
        parent::Controller();
   }

function index()
{

    $errMsg     = '' ;
        if($this->input->post('adminUsername') && $this->input->post('adminPassword')){
                    $user_name = $this->input->post('adminUsername');
                    $pass_word = base64_encode($this->input->post('adminPassword'));
                    $query=$this->db->get_where('gm_adminusers',array('adminUsername'=>$user_name,'adminPassword'=>$pass_word,'admin_status'=>'A'));
                    print_r($query);

                    if ($query->num_rows() > 0)
                    {
                            $arrRow =$query->row_array();
                            $newdata = array(
                             'sess_adminId'  =>$arrRow['adminId'],

                       );
                       $this->db_session->set_userdata($newdata);
                        if($this->db_session->userdata('sess_adminId')){
                                    redirect('user/home');
                                }
                                else{
                                    $errMsg ='<span style="color:red">Login Error :Please Check Your input.</span>';    
                                    /*redirect('user/home');    */
                                }   

                    }else{
                    $errMsg ='<span style="color:red">Critical Error:Contact Your Administrator</span>';    


                    }
    }

    $data['errMsg']         = $errMsg;
    $this->load->view('header');
    $this->load->view('index',$data);
    $this->load->view('footer');

}

enter image description here

enter image description here

Upvotes: 0

Views: 89

Answers (1)

gen_Eric
gen_Eric

Reputation: 227200

Returning 0 rows is not an "error". It's a valid response to a valid MySQL query. Why is the query returning 0 rows? Because the username and password didn't match.

I assume you are typing 123456 in as your password. No matter how hard you try, when you do base64_encode('123456') you're not gonna get 123456.

What you need to do is remove base64_encode and replace it with a real password solution. PHP 5.5 has one built-in (http://www.php.net/manual/en/ref.password.php)1.

You're gonna need to re-save all your passwords in your database, obviously. Also, make sure to store them all in the same format. You currently have one in plaintext and the other as base64.

1 If you don't have PHP 5.5, you can try this: https://github.com/ircmaxell/password_compat

Upvotes: 1

Related Questions