Welcome Guest, Not a member yet? Register   Sign In
Query error in Model
#1

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
Reply
#2

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
Reply
#4

(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
Reply
#5

(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
Reply
#6

Have a look at InsiteFX's reply.
Reply
#7

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

Will do!!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB