Thanks a lot Thomas for this wonderful book though the codes are not working 100%.
I started to copy the part of the code as soon as I am instructed to do so . I mean I am just following your book. So far I done up to chapter 4. I skipped chapter 5 (cart) and started to build the dashboard. At this point I am facing problem with admin login.
Here are my model, view and controller:
Code:
class MAdmins extends Model{
function __construct(){
parent::Model();
}
function verifyUser($u,$pw){
$this->db->select('id,username');
$this->db->where('username',db_clean($u,16));
$this->db->where('password', db_clean(dohash($pw),16));
$this->db->where('status', 'active');
$this->db->limit(1);
$Q = $this->db->get('admins');
if ($Q->num_rows() > 0){
$row = $Q->row_array();
$_SESSION['userid'] = $row['id'];
$_SESSION['username'] = $row['username'];
}else{
$_SESSION['userid'] = 0;
$this->session->set_flashdata('error', 'Sorry, your username or password is incorrect!');
}
}
}
Code:
function verify(){
if ($this->input->post('username')){
$u = $this->input->post('username');
$pw = $this->input->post('password');
$this->MAdmins->verifyUser($u,$pw);
if ($_SESSION['userid'] > 0){
redirect('admin/dashboard','refresh');
}
}
$data['main'] = 'login';
$data['title'] = "S & G Suppliers - Admin Login";
$data['navlist'] = $this->MCats->getCategoriesNav();
$this->load->vars($data);
$this->load->view('template', $data);
}
Code:
<h2>Please login to Access the Dashboard</h2>
<?php
if ($this->session->flashdata('error')){
//echo "<div class='message'>";
echo $this->session->flashdata('error');
//echo "</div>";
}
$udata = array('name'=>'username','id'=>'u','size'=>15);
$pdata = array('name'=>'password','id'=>'p','size'=>15);
echo form_open("sellside/verify");
echo "<p><label for='u'>Username</label><br/>";
echo form_input($udata) . "</p>";
echo "<p><label for='p'>Password</label><br/>";
echo form_password($pdata) . "</p>";
echo form_submit('submit','login');
echo form_close();
?>
Code:
class Dashboard extends Controller {
function __construct(){
parent::Controller();
session_start();
/*if ($_SESSION['userid'] < 1){
redirect('sellside/verify','refresh');
}*/
}
First of all the error tells me that:
"
Fatal error: Call to undefined function db_clean() in
C:\wamp\www\s_g_suppliers\system\application\model s\madmins.php on line
11"
"
Fatal error: Call to undefined function dohash() in
C:\wamp\www\s_g_suppliers\system\application\model s\madmins.php on line
12"
If I remove the functions then I cannot simple log in. I think the problem is because of not using the dohash() the password is not matched with the actual entry. Why it says that the functions are invalid. A I told you i did not copy the entire codes after I downloaded it. I downloaded CI and started to change it according to your book. Is there any place where I should add some librery functions?