Thanks Jeremy, I caught that one myself a little while ago in the manual
query, I should have updated this post.

My original concern was why I couldn't get this script to run the update:

[code]

$date = date('Y-m-d H:i:s');

$this->User->read(null, $id);

$this->User->set(array(
   'approved' => 1,
   'last_login' => $date,
   'activation_code' => ''
   )
 );
$this->User->save();

[/code]

I used it to run an update in a different action and it worked. Is it the
right script for the job or am I just barking up the wrong tree? No matter
which way I write the date in this one it just won't take and I kept it
almost identical to the one that works (or does it? now I need to go double
check). K, I double checked and it does indeed work.

- Ed



On Tue, May 18, 2010 at 11:44 PM, Jeremy Burns <[email protected]> wrote:

> Ed - I think you need some apostrophes or speech marks around your date
> field. If you look at the first update statement:
>
> UPDATE users SET approved = 1, last_login = 2010-05-18 16:54,
> activation_code = '' WHERE id = 1937
>
> ...this would *probably work if it were changed to:
>
> UPDATE users SET approved = 1, last_login = '2010-05-18 16:54',
> activation_code = '' WHERE id = 1937
>
>
> Jeremy Burns
> [email protected] <[email protected]>
>
>
> On 19 May 2010, at 01:07, Ed Propsner wrote:
>
> 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
>
>
>  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]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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