geoffs3310
geoffs3310

Reputation: 14008

cakephp updateAll not working

I have the following code:

$this->Permissions->updateAll(
    array('Permissions.user' => $newuser), 
    array('Permissions.user' => $originaluser)
);

But when I run it I get the following error:

Warning (512): SQL Error: 1054: Unknown column 'counterstaff' in 'field list' [APP\cake\cake\libs\model\datasources\dbo_source.php, line 681]

Query: UPDATE `permissions` AS `Permissions` SET `Permissions`.`user` = counterstaff WHERE `Permissions`.`user` = 'counter' 

for some reason it thinks the value that I want to set is a column. Anyone have any ideas why this is the happening?

Upvotes: 4

Views: 9131

Answers (3)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

**Use this code for updating your data:** 
$this->Permissions->updateAll(
        array('Permissions.user' => "'$newuser'"), 
        array('Permissions.user' => "'$originaluser'")
    );

Upvotes: 3

Shakti Singh
Shakti Singh

Reputation: 86406

Problem with the update query is put the value in quotation something like

    UPDATE `permissions` AS `Permissions` SET
 `Permissions`.`user` = "counterstaff" WHERE 
`Permissions`.`user` = 'counter' 

Upvotes: -2

geoffs3310
geoffs3310

Reputation: 14008

Fixed it! I had to add single quotes around my variable like so:

$this->Permissions->updateAll(
    array('Permissions.user' => "'".$newuser."'"), 
    array('Permissions.user' => $originaluser)
);

Upvotes: 15

Related Questions