Change a databasefield on function call

I tried to change a database field everytime a function is called. But it doesn't work. Any ideas or is this complete wrong.

public function changetaskAction($taskitem_id) {

  $task = Tasks::find(array(
    "taskitem_id = $taskitem_id"
    ));

  if (count($task) == 0) {
      $this->flash->error("Task does not exist");
      return $this->forward("tasks/index");
    }

    if ($task->ready="0") {
        $ready = "0";
    } else {
        $ready = "1";
    }
    $task->ready = $ready;
    if ($task->update() == false) {
        foreach ($task->getMessages() as $message) {
            $this->flash->error($message);
        }
      } else {
        $this->flash->success("Task was updated successfully");
        return $this->forward("tasks/index");
    }
  }


2.8k
edited Jul '15

Hmm, maybe you should try if($task->ready == "0") instead of if($task->ready = "0")

PS: You should protect your Database-activity against SQL Injection in line 4. ("taskitem_id = $taskitem_id")



1.1k

I think there is someting else wrong because the log say's "could not be converted to string". Thank you for pointing me to line 4!



2.8k

Which log do you exatcly mean?



1.1k

The apache log and is referring to line 12: if ($task->ready="0")



2.8k

Try change this entire line to the following:

if($task->ready == 0)

Now you check the state of $task->ready and doesn't set it to "0". That should be the error.