Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:42:53+00:00 2026-06-17T21:42:53+00:00

I have the following code in a CI app : $query = INSERT INTO

  • 0

I have the following code in a CI app :

$query = "INSERT INTO user(user_name,user_email) VALUES(?,?)";
        $result = $this->db->query($query,array($userName,$email));
        if ($result->num_rows()>0)
            return $this->db->insert_id();
        else
            return null;

This yields an error ; Fatal error: Call to a member function num_rows() on a non-object in C:\xampp\htdocs\cmdline\application\models\mlogin.php on line 38

line 38 is the condition for number of rows is greater than 0 .
Now I don’t get what is happening – I am using CI’s documentation to check whether number of rows is greater than 0 , why does this fail ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:42:54+00:00Added an answer on June 17, 2026 at 9:42 pm

    It’s because you’re doing an INSERT query. Queries that modify data return TRUE in all cases, so what you’re really attempting is TRUE->num_rows(), which doesn’t make any sense, causing an error.

    What you actually want to check is $this->db->affected_rows(), which will tell you how many rows were inserted into the database.

    Although you’re not doing it in this case, it’s worth noting that affected_rows() will only return the count of rows that actually changed during the query, so UPDATE queries that don’t actually modify data (i.e. if the field already has the value the query is trying to set it to), then that row won’t be reflected in the affected_rows() value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $this->Permissions->updateAll( array('Permissions.user' => $newuser), array('Permissions.user' => $originaluser) ); But
Let's say I have the following code in Google App Engine: from urllib import
In my Zend Framework app, I have following code: index.php $app_started_time = time(); layout.phtml
I have the following code in my Backbone app, Is there a way to
I have the following code that allows my console app to go to the
I have the following code: <fx:Script> <![CDATA[ import shared.GlobalsManager; import app.Globals; protected var globals:Globals=GlobalsManager.getGlobals();
In my viewDidLoad method of my iPhone app I have the following code: zombie[i].animationImages
I'm doing a small app in Excel, and I have the following code when
Im trying to get debugging working without an app.config. I have the following code:
So, I'm finishing up an iPhone App. I have the following code in place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.