Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp updateAll not working

Tags:

cakephp

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?

like image 247
geoffs3310 Avatar asked Dec 05 '22 00:12

geoffs3310


2 Answers

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

$this->Permissions->updateAll(
    array('Permissions.user' => "'".$newuser."'"), 
    array('Permissions.user' => $originaluser)
);
like image 73
geoffs3310 Avatar answered Jan 11 '23 18:01

geoffs3310


**Use this code for updating your data:** 
$this->Permissions->updateAll(
        array('Permissions.user' => "'$newuser'"), 
        array('Permissions.user' => "'$originaluser'")
    );
like image 25
Indrajeet Singh Avatar answered Jan 11 '23 16:01

Indrajeet Singh