CakePHP tutorial: database update data

Hi guys! In this tutorial I will speak again about CakePHP Framework. I will explain to you how you can update data in database with CakePHP.

I have a table in my database called posts with two columns: id and title.

Now, I will create a sample form in my view file:

<?php
echo $this->Form->create('post');

echo $this->Form->input('title');

echo $this->Form->end('Add');
?>

Next, I will create a new function in my Controller with this code:

public function index() {
$this->layout = false;
if($this->request->is('post')):
$this->Post->read(null, 15); // this code will get information where id is 15
$this->Post->set('title', $this->request->data["post"]["title"]); // this code will add information in the title column
$this->Post->save(); // this code will update the table
endif;
}

Video tutorial:









Leave a Comment