Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- </head>
- <body>
- <div class="container">
- <h3>Login</h3>
- <hr>
- <form action="<?php echo base_url('login/do_login')?>" method="POST">
- <div class="form-group">
- <label for="cari">USERNAME</label>
- <input type="text" name="usuario" id="usuario" class="form-control">
- </div>
- <div class="form-group">
- <label for="cari">PASSWORD</label>
- <input type="password" name="contrasena" id="contrasena" class="form-control">
- </div>
- <input class="btn btn-primary" type="submit" value="Login" name="login">
- <input class="btn btn-primary" type="reset" value="Reset">
- </form>
- </div>
- </body>
- </html>
- <?php
- Class Login extends CI_Controller{
- public function index(){
- $this->load->view('login_form');
- }
- public function do_login()
- {
- // load the form_validation library
- $this->load->library('form_validation');
- $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
- $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');
- // if there is errors
- if ($this->form_validation->run() == FALSE) {
- // this will load your form with the errors
- $this->load->view('login_form');
- } else {
- // if no errors we will hit the database
- $user=$this->input->post('usuario', true);
- $pass=$this->input->post('contrasena', true);
- $cek = $this->m_login->proceso_login($user,$pass);
- $hasil=count($cek);
- if($hasil > 0){
- $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
- if($pelogin ->type == 0){
- redirect('login/admin');
- }
- else{
- redirect('login/usuario');
- }
- }
- redirect('login/index');
- }
- }
- public function home(){
- $data['records']=$this->m_login->getDetails();
- $this->load->view('usuario',$data);
- }
- public function getDetails()
- {
- $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
- ->join('usuarios','usuarios.id=cursadas.user_id')
- ->join('materias','materias.id=cursadas.subject_id')
- ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
- ->get()->result_array();
- return $st[0]; // or use the row function
- }
- <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
- <thead>
- <th>id</th>
- <th>User</th>
- <th>Subject</th>
- <th>Grade</th>
- <th>Date</th>
- </thead>
- <tbody>
- <?php
- if (count($records) > 0) {
- foreach($records as $record) {
- echo "<tr>
- <td>".$record['id']."</td>
- <td>".$record['User']."</td>
- <td>".$record['name']."</td>
- <td>".$record['grade']."</td>
- <td>".$record['date']."</td>
- </tr>";
- }
- }
- ?>
- </tbody>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement