I'm really not sure what the deal is here. This works for an update:

[code]

                        $id = $find['User']['id'];
$this->User->query("UPDATE users SET `approved` = 1, `activation_code` = ''
WHERE id = $id");
$this->User->id = $id;
$this->User->saveField('last_login', date('Y-m-d H:i:s') );

[/code]

Was I doing something wrong originally? It seems to me like the other way
should have worked (I used that set up for updates in other actions), but
hey ... what do i know?
If anyone is able to explain the error in my ways I would sure like know.

Thanks,
- Ed

On Tue, May 18, 2010 at 5:37 PM, Ed Propsner <[email protected]> wrote:

> I'm trying to update a record (last login field) and having problems with
> it. I can't see where the error is.
>
>  Table col -> `last_login` datetime NOT NULL
>
> [code]
>
> $date = date('Y-m-d H:i:s');
>
> $this->User->read(null, $id);   <------- debug here returns a complete
> array as I would expect
>
> $this->User->set(array(
>    'approved' => 1,
>    'last_login' => $date,
>    'activation_code' => ''
>    )
>  );
>  $this->User->save();
>
> [/code]
>
> The script moves right past the update like it wasn't even there.
>
> When I try to manually update for the sake of troubleshooting:
>
> $this->User->query("UPDATE users SET approved = 1, last_login = $date,
> activation_code = '' WHERE id = $id");
>
> You have an error in your SQL syntax; check the manual that corresponds to 
> your MySQL server version for the right syntax to use near '16:54, 
> activation_code = '' WHERE id = 1937' at line 1
>
> *Query:* UPDATE users SET approved = 1, last_login = 2010-05-18 16:54, 
> activation_code = '' WHERE id = 1937
>
> If I make the change:
>
> $date = date('Y-m-d H:i:s');  TO ---> $date = date('Y-m-d'); (essentially 
> changing it to date instead of datetime) the manual update goes through but 
> $this->User->set still does not.
>
> It's been a long day and perhaps I'm missing something but the query seems
> okay, no? I could understand the error if the table was set up for date
> instead of datetime, but that's not the case (`last_login` datetime NOT
> NULL)
>
> The login action updates the same field using 'saveField' and has no
> issues.
>
> What am I overlooking here?
>
> - Ed
>
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to