Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:38:33+00:00 2026-06-03T05:38:33+00:00

I am using cakePHP why won’t the name insert into the table, a null

  • 0

I am using cakePHP why won’t the name insert into the table, a null value seams to be passed as the table is updated but with out the name?

Table in Database

CREATE TABLE tests (
id serial not null unique primary key,
name varchar,
created timestamp default CURRENT_TIMESTAMP

) 

add.ctp

<?php
echo $this->Form->create('Post');
echo $this->Form->input('name');
echo $this->Form->end('RSVP');
?>

Test Model

<?php
class Test extends AppModel {
var $name = 'Test';
}

TestContoller

<?php
class TestController extends AppController {
public $helpers = array('Html', 'Form');

var $name = "Test";


public function index() {
    $this->set('tests', $this->Test->find('all'));
}

public function view($id = null) {
    $this->Test->id = $id;
    $this->set('Test', $this->Test->read());
}

public function add() {
    if ($this->request->is('post')) {
        if ($this->Test->save($this->request->data)) {
            $this->Session->setFlash('Your post has been saved.');
            $this->redirect(array('action' => 'index'));
        } 
        else {
            $this->Session->setFlash('Unable to add your post.');
        }
    }
}

public function edit($id = null) {
    $this->Test->id = $id;
    if ($this->request->is('get')) {
        $this->request->data = $this->Post->read();
    } 
    else {
        if ($this->Test->save($this->request->data)) {
            $this->Session->setFlash('Your post has been updated.');
            $this->redirect(array('action' => 'index'));
        } 
        else {
            $this->Session->setFlash('Unable to update your post.');
        }
    }
}

public function delete($id) {
        if ($this->request->is('get')) {
            throw new MethodNotAllowedException();
        }
        if ($this->Test->delete($id)) {
            $this->Session->setFlash('The post with id: ' . $id . ' has been deleted.');
            $this->redirect(array('action' => 'index'));
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:38:35+00:00Added an answer on June 3, 2026 at 5:38 am

    In your method you missed to include $this->Test->create();, which will add new row to table and inset new data to it.

    public function add() {
        if ($this->request->is('post')) {
            $this->Test->create(); // missed this line
            if ($this->Test->save($this->request->data)) {
                $this->Session->setFlash('Your post has been saved.');
                $this->redirect(array('action' => 'index'));
            } 
            else {
                $this->Session->setFlash('Unable to add your post.');
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using CakePHP 1.3 there are named parameters in the URL like .../name:value/... These are
I'm using CakePHP to build an application using the MVC Pattern, but my question
I'm using CakePHP but it's a question about the MVC pattern. I have in
I'm using cakephp and trying to check if a table has data entered in
Using cakephp, I have a generic address table, which I want to link to
I'm using CakePHP 2.0. I have 2 models/controllers (Category/Coupon): // File: Model/Coupon.php // Table
I'm using CakePHP 2.0.5 (but this isn't necessarily a cakephp specific question). I have
Using CakePHP 1.3.6 I'm sure I may have to add code and examples, but
Using CakePHP (On PHP 5.2.6) I do a list query on a table which
I'm using cakePHP and I want to add a First and Last name column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.