Welcome Guest, Not a member yet? Register   Sign In
problem in getting result from model.
#1

[eluser]Ram Krishna[/eluser]
i am developing admin panel.In which i am developing admin login.
the code is below...
controller code
Code:
<?php
class Admin extends CI_Controller
{
function index()
{
echo "This is Great";
}
function login()
{
$this->load->view('admin_login_form');
}
function confirm_login()
{

$this->load->model('admin_model');
$query=$this->admin_model->dbread();

if($query ==true)
{
echo "login successful";
}
else
{
echo "wrong username or password";

}
}
}
?>
and model
Code:
<?php
class Admin_model extends CI_Model {

function dbread()
{
$this->db->where('admin_name',$this->input->post('username'));
$this->db->where('password',$this->input->post('password'));
$query = $this->db->get('admin');

if($query->num_rows() == 1)
{
return true;
}
else
{
return false;
}

}
}
?>
And
view
Code:
<div class="admin_login">
<h3>Admin Login</h3>
&lt;?php echo form_open('admin/confirm_login'); ?&gt;
&lt;?php echo form_input('username','username'); ?&gt;
&lt;?php echo form_password('password','password'); ?&gt;
&lt;?php echo form_submit('submit','Login');?&gt;
&lt;?php echo form_close(); ?&gt;
&lt;?php ?&gt;
</div>
on login this code always returns wrong username or password OR we can say dbread function of model alway return false.
please give me a solution.
#2

[eluser]dnc[/eluser]
Try putting


Code:
echo $this->db->last_query();
exit();


After
Code:
$query = $this->db->get('admin');


to see what the query is that you are sending to the database.
#3

[eluser]Chathuranga Tennakoon[/eluser]
make sure that you have loaded the DB model inside your controller. it is a good practice to autolod the database in you application configuration files.
#4

[eluser]boltsabre[/eluser]
>> it is a good practice to autolod the database in you application configuration files.

That's not true, it completely depends on the application. If Ram has an huge website, but only a small admin panel area (perhaps it's a cms site?) and the admin panel is the only place you need a DB connection why would you autoload it cross the whole site? In this case it would make much more sense to just load it in the admin constructor.

Anyway, if he didn't have a DB connection there would be a pretty obvious error message! Same if the model wan't being loaded!
#5

[eluser]boltsabre[/eluser]
Are the passwords in the DB hashed? If so they won't match your user input password unless you hash them as well...




Theme © iAndrew 2016 - Forum software by © MyBB