Home >>Codeigniter Tutorial >Create login form in Codeigniter
Table Name : student | |
student_id | int primary key auto_increment |
name | char(50) |
varchar(100) | |
password | varchar(100) |
mobile | bigint |
course | char(100) |
<?php class User extends CI_Controller { public function __construct() { parent::__construct(); $this->load->database(); $this->load->helper('url'); } public function login() { if($this->input->post('login')) { $e=$this->input->post('email'); $p=$this->input->post('pass'); $que=$this->db->query("select * from student where email='".$e."' and password='$p'"); $row = $que->num_rows(); if($row) { redirect('User/dashboard'); } else { $data['error']="<h3 style='color:red'>Invalid login details</h3>"; } } $this->load->view('login',@$data); } function dashboard() { $this->load->view('dashboard'); } } ?>
<!DOCTYPE html> <html> <head> <title>Login form</title> </head> <body> <form method="post"> <table width="600" align="center" border="1" cellspacing="5" cellpadding="5"> <tr> <td colspan="2"><?php echo @$error; ?></td> </tr> <tr> <td>Enter Your Email </td> <td><input type="text" name="email"/></td> </tr> <tr> <td width="230">Enter Your Password </td> <td width="329"><input type="password" name="pass"/></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="login" value="Login"/></td> </tr> </table> </form> </body> </html>
<!DOCTYPE html> <html> <head> <title>Student Dashboard</title> </head> <body> <h1>Welcome to your dashboard...</h1> </body> </html>