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

  • SEARCH
  • Home
  • 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 3302494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:51:28+00:00 2026-05-17T20:51:28+00:00

Hello I am using cakePHP 1.3 and I am unable to retreive the last

  • 0

Hello I am using cakePHP 1.3 and I am unable to retreive the last inserted row’s id. I actually am using $this->Model->id to retreive the last inserted id but I am unable to get the id. When tried to check what is return type, it says as bool(false), which means nothing is returned.

Here I am loading a different model in a different controller, so would that be the issue?? But even though I am loading, I get back nothing!!

$this->loadModel('Contact');
$this->Contact->query("insert into contacts(tblContact_firstName,tblContact_lastName,tblContact_company,tblContact_department,tblContact_address,tblContact_country,tblContact_city,tblContact_state,tblContact_zipcode,tblContact_phone1,tblContact_email1) values('$sanitizedFormData[fname]','$sanitizedFormData[lname]','','$sanitizedFormData[company]','$sanitizedFormData[address]','$sanitizedFormData[country]','$sanitizedFormData[city]','$sanitizedFormData[state]','$sanitizedFormData[zip]','$sanitizedFormData[phone]','$sanitizedFormData[email]');");

$this->loadModel('Contact');
$contactId = $this->Contact->id;

And when I printed the $this->Contact array recursively, I found the value of “id” key empty. So that explains why I was receiving an empty value.

Now given my situation, how would I get the last inserted id, specific to the controller Contact?

  • 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-05-17T20:51:28+00:00Added an answer on May 17, 2026 at 8:51 pm

    When you use query() you loose a lot of automagic cakephp provides. Use save() instead.

    In fact, you even do not need to load Contact in this case. You can execute any query from the current controller with query() even saving to any other table.

    You can also avoid using loadModel() if your current model is somehow associated with Contact ($this->CurrentModel->AnotherOne->Contact->save(...)).

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

Sidebar

Related Questions

hello im using this code to do search <form action=arama.php method=get> <input type=text name=lol>
Hello i am using the latest version of artoolkit, and succesfully compiled simplevrml, but
Hello I'm using this star rating widget http://www.fyneworks.com/jquery/star-rating/ to add functionality for users to
I have this problem when trying to run hello world program using android SDK.
I'm using CakePHP to send an email. My controller code looks like: if ($this->User->save($this->request->data))
Hello I am using facebook graph api..and trying to display comments of each post..But
Hello i am using this tutorial to set the spinwheel for my webview ,
hello i'm using this .htaccess code to redirect urls. RewriteEngine on RewriteRule ^printer/([^/\.]+)/?$ printer.php?id=$1
Hello I am using this command to find text within files in linux find
hello im using VB 2008 is it possible to get active window name or

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.