Show details of an active user after login in codeigniter

Related searches

I want to show the details of the user right after login. here is my code :

---Model---

function getDetailsLogin($nama_serv, $no_polisi_serv, $kendaraan_serv, $lokasi_serv, $tgl_serv, $waktu_serv){
        $this ->db-> select('id_service, nama_serv, no_polisi_serv, kendaraan_serv','lokasi_serv','tgl_serv','waktu_serv');
        $this ->db-> from('service');
        $this ->db-> where('nama_serv', $nama_serv);
        $this ->db-> where('no_polisi_serv', $no_polisi_serv);
        $this ->db-> where('kendaraan_serv', $kendaraan_serv);
        $this ->db-> where('lokasi_serv', $lokasi_serv);
        $this ->db-> where('tgl_serv', $tgl_serv);
        $this ->db-> where('waktu_serv', $waktu_serv);
        $query = $this ->db-> get();
        return $query->result();
    }

---Controller---

    public function index(){
        $data['konsumen']=$this->Mymodel->getDetailsLogin(
            'nama_serv', 
            'no_polisi_serv', 
            'kendaraan_serv', 
            'lokasi_serv', 
            'tgl_serv', 
            'waktu_serv'
        );
        $this->load->view('Home/title');
        $this->load->view('Home/navbar');
        $this->load->view('Konsumen/konsumen',$data);
        $this->load->view('Home/footer');
    }

---View---

  <?php foreach ($konsumen as $key): ?>
    <?php echo $key->nama_serv; ?><br>
    <?php echo $key->no_polisi_serv; ?><br>
    <?php echo $key->kendaraan_serv; ?><br>
  <?php endforeach ?>

After i run the code it didn't show anything

EDIT : So what i want to do is after the users doing registration, users can login, and after login users can see their details informations that they put in the registration form. i already pass the login session, now i want to show user detail informations

and this is my database

$data['konsumen']=$this->Mymodel->getDetailsLogin(
            'nama_serv', 
            'no_polisi_serv', 
            'kendaraan_serv', 
            'lokasi_serv', 
            'tgl_serv', 
            'waktu_serv'
        );

Here in this function don't you need to give values? it looks like you are sending to the function the name of the columns and not the values you want to query by

You could try after

    $query = $this ->db-> get();

to add

$str = $this->db->last_query();
die($str)

that will give you the query.

After you the query run in it on directly on the db to see what it returns

How to verify if a user is logged in?, I'm working on a function in which the user logs in and can access to its views but only if his/her account is activated. So far I and here is the view in which I register a new account: <?php echo form_radio('active', 0, FALSE); ?> No Let the method login return an error code instead of the user id, i.e.: display user name and profile picture after login codeigniter and user name on index after login Codeigniter 3 Tutorial In Hindi #16 How to Create User Dashboard and Show User

Try using this on your model :

function getDetailsLogin($nama_serv, $no_polisi_serv, $kendaraan_serv, $lokasi_serv, $tgl_serv, $waktu_serv){
    $this ->db-> select('id_service, nama_serv, no_polisi_serv, kendaraan_serv','lokasi_serv','tgl_serv','waktu_serv');
    $this->db->from('service');
    $this->db->where('nama_serv', $nama_serv);
    $this->db->where('no_polisi_serv', $no_polisi_serv);
    $this->db->where('kendaraan_serv', $kendaraan_serv);
    $this->db->where('lokasi_serv', $lokasi_serv);
    $this->db->where('tgl_serv', $tgl_serv);
    $this->db->where('waktu_serv', $waktu_serv);
    $query = $this ->db-> get();
    return $query->row();
}

If you want to show only 1 (one) person's data, then you don't need a foreach.

In your View do this :

Nama Service : <?= $key->nama_serv; ?>
Nomor Polisi : <?= $key->no_polisi_serv; ?>
Kendaraan : <?= $key->kendaraan_serv; ?>

Salam~

How to check if user is banned., I have successfully made login with sessions with codeigniter 3 with logout page that shows how many users are still logged in after you have gone. the where clause in your query to retrieve the number of active sessions. Complete User Authentication System in CodeIgniter – 9 Steps. Creating User Authentication System in CodeIgniter that is User Registration and Login features, you will learn about how we can create these features in CodeIgniter. First, we will start off with creating a database table, then set up controllers views and routes.

I'm not sure what your db design is (if this answer doesn't fix the issue please post an image of the schema in your question), but your where statements seem useless e.g. nama_serv = 'nama_serv'.

I think you want this:

function getDetailsLogin(){
        $this->db->select('id_service, nama_serv, no_polisi_serv, kendaraan_serv','lokasi_serv','tgl_serv','waktu_serv');
        $this->db->from('service');
        $this->db->where('primary_key_field', $this->session->userdata('id'));
        $query = $this->db->get();
        if ($query->num_rows() == 1) {
            return $query->row(); // because you just want 1! no foreach required in view.
        }
        return false; // this should never have happened as the user is supposed to be logged in and have a valid session id.
    }

where primary_key_field is the unique identifier for the current user and userdata('id') is the session variable that holds it.

how many are logged in?, Handling Multiple Environments � Alternate PHP Syntax for View Files The Session class permits you maintain a user's “state” and track their activity while This detail was at the root of many issues and the main reason why So, what you need is to close the session for the current request after you no longer need it . Get the logged-in user’s account information using getRows () method of User model. Pass user data and load the account details view. login () –. Initially, load the login form view. If the form is submitted, Validate the posted fields data using CodeIgniter Form Validation library.

Finally got it. Damn it took me the whole night to figure it out

Since i'm using e-mail for login, then it suppose to be

    function getDetailsLogin(){
        $this ->db-> select('*');
        $this->db->from('service');
        $this->db->where('email_serv', $this->session->userdata('email_serv'));
        $query = $this ->db->get()->row();
        return $query;
    }

after that, i call it in the view

<?php echo $this->Mymodel->getDetailsLogin()->nama_serv; ?>

no need the controller

Also Thanks for everyone who trying to help this idiot, really appreciate it :)

Session Library — CodeIgniter 3.1.11 documentation, The function of show method is to fetch the data from users table and send it to users. php view. In above code first, we load the user_model file and then call the get_users( ) method to fetch the registered user data. At the end of code we are sending that data to user view. If a user is not logged in then the user is redirected to the login page with a flash message. public function login() {…} loads the login view located in sessions directory. public function authenticate() {…} sets the session user data for the keys logged_in and username. NOTE: We are not verifying any login details against the database.

How to make login, signup and user listing in codeigniter?, “It is very HARD to create multi level user login using Codeigniter.” Good news: Well, it turns out. You can easily create multi level user login using Codeigniter right now.! Today, In this tutorial, I will share with you how to create multi level user login using codeigniter. Step by step.

In this codeiniter user login and registration system, we will create two forms to show a login and registration. We will validate user data on server side, when user submits an empty form, it can display error message. After successfully registering or logging in, we will redirect the user to the dashboard.

We also have a paid ready-to-use advance login & registration module built on CodeIgniter that you can check out at CodeIgniter Login Registration Form. Creating sessions in CodeIgniter is different from simple PHP.

Comments
  • did you debug it? like in mode are you getting any data? Did you do check your query with $this->db->last_query();die; before return
  • sorry i'm a newbie so i don't really get it. when i add that query check before result, it shows SELECT `id_service`, `nama_serv`, `no_polisi_serv`, `kendaraan_serv` FROM `service` WHERE `nama_serv` = 'nama_serv' AND `no_polisi_serv` = 'no_polisi_serv' AND `kendaraan_serv` = 'kendaraan_serv' AND `lokasi_serv` = 'lokasi_serv' AND `tgl_serv` = 'tgl_serv' AND `waktu_serv` = 'waktu_serv'
  • These are ('nama_serv', 'no_polisi_serv', 'kendaraan_serv', 'lokasi_serv', 'tgl_serv', 'waktu_serv') column names. You should send values from controller to model
  • ohh okay, then how do i do that?
  • why so many where statements? and why do they all reference themselves? e.g. nama_serv = nama_serv ... weird. what is the primary key of the table you use to identify a single user? can you post an image of your database? please try and answer all of my questions.
  • so first, i'm doing registration to input name, password, etc to the database. After that i'm trying to login. I did it, the session is active. now the problem i need to show the details of the active user
  • What does $str = $this->db->last_query(); die($str) this return to you ? if you run it with workbench or phpmyadmin does it return any data?
  • SELECT `id_service`, `nama_serv`, `no_polisi_serv`, `kendaraan_serv` FROM `service` WHERE `nama_serv` = 'nama_serv' AND `no_polisi_serv` = 'no_polisi_serv' AND `kendaraan_serv` = 'kendaraan_serv' AND `lokasi_serv` = 'lokasi_serv' AND `tgl_serv` = 'tgl_serv' AND `waktu_serv` = 'waktu_serv'
  • and if you run that on the db via mysqlworkbench or phpmyadmin or any other db client what does it return?
  • then your query is wrong, try changing the where so that the query returns a result