Code igniter : Call to a member function num_rows() on a non-object
13,799
well i came up a solution by myself ..actually it was not loading the database and thus when i want to query and selecting the result i was getting this error and finally when i checked my databse.php file there is a white space in the name of database so i removed it .. thanks for all of you
Related videos on Youtube
Author by
mynameisjohn
Updated on June 04, 2022Comments
-
mynameisjohn almost 2 years
i have developed a app in codeigniter on localhost ...the app works fine .. then i uploaded the app into temporary server ... and after login into the admin panel i am getting this error..but if i run the same app in localhost it works fine ...
error
Fatal error: Call to a member function num_rows() on a non-object in /home/u520606051/public_html/application/models/loginmodel.php on line 9
this my Model :
function validate($data) { $query = $this->db->get_where('users', $data); if($query->num_rows() == 1) { return true; } }
controller
function verifyUser() { //getting parameters from view $data = array( 'username' => $this->input->post('username'), 'password' => $this->input->post('password') ); $this->load->model('loginModel'); $query = $this->loginModel->validate($data); if ($query) { //if the user c validated //data variable is created becx we want to put username in session $data = array( 'username' => $this->input->post('username'), 'is_logged_in' => true ); $this->session->set_userdata($data); redirect('sessionController/dashboard_area'); } else { $this->index(); } }
file name Of Modal:
loginmodel.php class Loginmodel extends CI_Model
file name of Controller
loginController.php class LoginController extends CI_Controller
-
R. Schaaphuizen about 11 yearsThe models itself is loading, otherwise this model can't throw the error. filenames should be working fine, i guess the $query is empty because it could not create the right object because an incorrect database connection.
-
jmadsen about 11 yearsYeah, I guess you're right, but still a little suspicious of: $this->load->model('loginModel'); Anyway, OP - your query is failing. Turn database debuggin gon in your Config file, and also try $this->db->last_query(); after the query line & see if it tells you anything - could be a schema or permissions issue, or something along those lines