CodeIgniter Forums
Fatal error: Call to a member function query() on a non-object in C:xampphtdocsFairozcodeignitorapplicationmodelslogin_m - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Fatal error: Call to a member function query() on a non-object in C:xampphtdocsFairozcodeignitorapplicationmodelslogin_m (/thread-55206.html)



Fatal error: Call to a member function query() on a non-object in C:xampphtdocsFairozcodeignitorapplicationmodelslogin_m - El Forum - 10-14-2012

[eluser]Unknown[/eluser]
Hi, I am new to codeignetor and trying to create a login form when i am trying to connect to the database the above error is displaying please anybody see the below script and please guide me to what should i change.


login.php //controller

<?php
class Login extends CI_Controller{
function __construct()
{
parent::__construct();
$this->today = date("d/m/Y");
}
function index()
{
$data['main_content'] = 'login_view';
$data['today'] = $this->today;
$this->load->view('includes/template', $data);
}
function login_process()
{
$this->load->model('login_model');
$data = array($this->input->post('user_name'), $this->input->post('pass'));
$this->login_model->check_login($this->input->post('user_name'), $this->input->post('pass'));
}
}
?>


login_view.php //view

<div>
&lt;?php $this->load->helper('Form'); ?&gt;
&lt;?php echo form_open('login/login_process'); ?&gt;
<table align="center">
<tr>
<td colspan="3" align="center"></td>
</tr>
<tr>
<td><b>User Name</u></td>
<td>:</td>
<td>&lt;input type="text" name="user_name"&gt;&lt;/td>
</tr>
<tr>
<td><b>Password</b></td>
<td>:</td>
<td>&lt;input type="password" name="pass"&gt;&lt;/td>
</tr>
<tr>
<td colspan="3" align="center">&lt;input type="submit" name="submit"&gt;&lt;/td>
</tr>
</table>
&lt;/form&gt;
<div>


login_model.php //model

&lt;?php
class Login_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function check_login($data1, $data2)
{
$sql = "SELECT * FROM admin WHERE Username = ? AND Pass = ?";

$num = $this->db->query($sql, array($data1, $data2));
if($num!= 0)
{
redirect('home_view', 'refresh');
}else{
$this->load->view('login_view');
}
}
}
?&gt;


Fatal error: Call to a member function query() on a non-object in C:xampphtdocsFairozcodeignitorapplicationmodelslogin_m - El Forum - 10-14-2012

[eluser]CroNiX[/eluser]
Are you loading the database library anywhere?