My problem is that I can't update the specific $userId. have the values I've selected. I also get an error:

Call to a member function where() on integer

I just started to learn Craft. It can be simple for you but not for me.

public function updateUserName($userId, $updateUser)

    $update = craft()->db->createCommand()->update('contest_user', array(
        'name' => $updateUser))->where('id', $userId);

    return $update;

When you take a look at the documentation the interface for the update function is the following.

public integer update(string $table, array $columns, mixed $conditions='', array $params=array ())

Thus your code should look like:

public function updateUserName($userId, $updateUser)
    $update = craft()->db->createCommand()->update(
        array('name' => $updateUser), 
        array(':id', $userId)

    return $update;

You can see a working example here:

// build and execute the following SQL:
// UPDATE `tbl_user` SET `name`=:name WHERE id=:id
$command->update('tbl_user', array(
), 'id=:id', array(':id'=>1));
  • Thx. It works. It's so easy when you think about it. I'm just a beginner. So there is plenty of practise to do.
    – olifantT
    Oct 16 '18 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.