CakePHP tutorial: insert data from form to database

Hi guys! In this tutorial I will speak you about how you can get data from a form. Moreover, I will explain to you how you can save it to database.

I have created a simple form:

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

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

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

Next, in my Controller I will check if form was submitted with this code:

if($this->request->is('post')):

endif;

Next, I will get data from title input:

$this->request->data['Post']['title'] = $this->request->data["post"]["title"];

And, to save it to my database(table: posts with two columns id and title) i will use this code:

$this->Post->save($this->request->data);

Video tutorial:









Leave a Comment