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 6016013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:55:20+00:00 2026-05-23T02:55:20+00:00

Using CakePHP 1.3 I’m trying to save some data to a MySQL database. The

  • 0

Using CakePHP 1.3 I’m trying to save some data to a MySQL database. The data doesn’t come from a form, but to imitate it I put the data in the $this -> data array like this:

$this -> data = Array (
                         'User' => Array (
                                            'last_login' => date ('Y-m-d H:i:s')
                                         )
                      );

This creates an array that looks exactly like the default Cake data array. So far so good.

Next, I call the following function:

if ($this -> User -> save ($this -> data))
{
   echo $this -> User -> id;
}
else
{
   echo 'Save failed';
}

It always comes up with ‘Save failed’, showing the data wasn’t saved correctly. I tried to debug this in a variety of ways:

I checked whether a beforeSave or beforeValidate function existed in my User model or AppModel and whether these return true. (They did.)

I echoed $this -> Session -> flash () in default.ctp. It doesn’t say anything.

I echoed $this -> element ('sql_dump') in default.ctp. I don’t see any sign of the query I expect, confirming my expectation of the query not executing instead of just failing.

From my controller I echoed $this -> validationErrors. It’s empty so validation seems to be ok.

I tried to provide the correct index in my $this -> data array for the save, like this:

$this -> User -> save ($this -> data['User']);

I checked whether I loaded my User model via $this -> loadModel ('User') (I did).

Note that I try to do this in my AppController (that’s why I loaded the model manually). More specifically: it’s in the beforeFilter () function in the AppController. This function is called in the beforeFilter () function in every other Controller my application has (I checked this).

At the moment, I don’t know what could cause this. Does anyone have an idea about this?

  • 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-23T02:55:21+00:00Added an answer on May 23, 2026 at 2:55 am

    You’re not specifying the User id before you save, so CakePHP has no idea what row to save the date to. In effect, you’re asking CakePHP to just save a date, without specifying where. I am away from my webdev box right now, but I believe this is what you’re looking for.

    if( ! isset( $this->User->id ) ) {
        $this->User->create();
    }
    $this->User->saveField('last_login', date(DATE_ATOM));
    

    See this page for more information. BTW, if you want to do it the way you were originally doing it, I think this is the way:

    if( ! isset( $this->User->id ) ) {
            $this->User->create();
            $myId = $this->User->getLastInsertID();
    } else {
      $myId = $this->User->id;
    }
    
    $this -> data = Array (
          'User' => Array (
          'id' => $myId
          'last_login' => date ('Y-m-d H:i:s')
       )
    );
    
    if ($this -> User -> save ($this -> data))
    {
       echo $this -> User -> id;
    }
    else
    {
       echo 'Save failed';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using CakePHP 1.3 , I post a form which correctly fills in $this->data .
I want to run a web application on php and mysql, using the CakePHP
I am using a very intrinsic database with a CakePHP application and so far
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using cakephp: I am trying to update customer information and the address the customer
Using CakePHP 1.2, I am trying produce a GROUP BY query: SELECT `categories`.*, COUNT(`entities`.id)
Using CakePHP, I created select-option form element with: echo $form->select('items', $numeration , array('selected' =>
Using CakePHP 1.3 I understand the example at http://book.cakephp.org/complete/1143/Data-Validation#Adding-your-own-Validation-Methods-1181 on how to add my
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
hi i am using cakephp for my project but i am fetching problem when

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.