CodeIgniter Forums
Query error in Model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Query error in Model (/thread-73586.html)



Query error in Model - Mekaboo - 05-12-2019

Hello!

Ive gotten this error:

Fatal error: Call to a member function num_rows() on a non-object in /home4/cultured/public_html/application/models/Login_model.php on line 12
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home4/cultured/public_html/application/controllers/Main.php:1)
Filename: core/Common.php
Line Number: 564
Backtrace:
A PHP Error was encountered
Severity: Error
Message: Call to a member function num_rows() on a non-object
Filename: models/Login_model.php
Line Number: 12
Backtrace:

This is my code within my model:
 <?php  
      
    class Login_model extends CI_Model {  
      
        public function log_in_correctly() {  
      
            $this->db->where('username', $this->input->post('username'));  
            $this->db->where('password', $this->input->post('password'));  
            $query = $this->db->get('cultured_codeignite');  
      
            
if ($query->num_rows() == 1)
            {  
                return true;  
            } else {  
                return false;  
            }  
      
        }  
      
          
    }  
    ?> 

Im trying correct the query row but dont know how to do it, Been researching but there are various awnsers and dont know which one is correct. Help if you can.

Heart Heart ,
Mekaboo


RE: Query error in Model - InsiteFX - 05-13-2019

It's telling you that before the query call some data was output to the view.

Headers already sent by your controller.

So some place in your code your trying to set the output again.


RE: Query error in Model - Wouter60 - 05-13-2019

I think there's an error in the query builder command. So $query is probably FALSE instead of an object.
Are you sure the table name is 'cultured_codeignite' ? No 'r' missing at the end?

If you've corrected that, you can return TRUE or FALSE like this:
PHP Code:
Return ($query->num_rows() == 1); 
So you don't need if .. else for that. The return value is either TRUE or FALSE.


RE: Query error in Model - Mekaboo - 05-13-2019

(05-13-2019, 03:03 AM)InsiteFX Wrote: It's telling you that before the query call some data was output to the view.

Headers already sent by your controller.

So some place in your code your trying to set the output again.

Okay thank you Blush


RE: Query error in Model - Mekaboo - 05-13-2019

(05-13-2019, 08:05 AM)Wouter60 Wrote: I think there's an error in the query builder command. So $query is probably FALSE instead of an object.
Are you sure the table name is 'cultured_codeignite' ? No 'r' missing at the end?

If you've corrected that, you can return TRUE or FALSE like this:
PHP Code:
Return ($query->num_rows() == 1); 
So you don't need if .. else for that. The return value is either TRUE or FALSE.

Hey I found the mistake (stupid me Tongue ): I named the DB and table the same thing. I created a new table but now getting this error in regards to sessions:

Severity: Warning
Message: session_start(): Cannot send session cache limiter - headers already sent (output started at /home4/cultured/public_html/application/controllers/Main.php:1)
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home4/cultured/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_regenerate_id(): Cannot regenerate session id - headers already sent
Filename: Session/Session.php
Line Number: 718
Backtrace:
File: /home4/cultured/public_html/index.php
Line: 315
Function: require_once


RE: Query error in Model - Wouter60 - 05-13-2019

Have a look at InsiteFX's reply.


RE: Query error in Model - Mekaboo - 05-13-2019

(05-13-2019, 01:37 PM)Wouter60 Wrote: Have a look at InsiteFX's reply.

Will do!!!