php - cakePHP 表单不向数据库发送数据

标签 php mysql database cakephp

我正在努力解决我的蛋糕代码(对 cakephp 来说非常新)并且需要一些帮助。我的代码的目的是从表单中获取数据,当用户点击注册时,它会将数据发送到我的数据库,但这并没有发生,而是当我点击注册时,页面正在重新加载。我目前使用 cake 2.0 和 wamp server 2.2

这是我的 individualcontroller.php 中的添加函数的代码

function addIndividual(){
    if($this->request->is('individuals')){
    {if ($this->Individual->save($this->request->data)) {
            $this->Session->setFlash('The user has been saved');
            $this->redirect(array('action' => 'index'));
        } else {
$this->Session->setFlash('The user could not be saved. Please, try again.');
        }
    }
}

} 代码在这里

这是我的 add_individual.ctp 中的代码,包括表单

   <h2>Please enter your details</h2>
<?php
echo $this->Form->create('individuals', array('action'=>'addIndividual'));
echo $this->Form->input('Title: ');
echo $this->Form->input('First Name: ');
echo $this->Form->input('Surname: ');
echo $this->Form->input('Street Address: ');
echo $this->Form->input('Suburb: ');
echo $this->Form->input('State: ');
echo $this->Form->input('Country: ');
echo $this->Form->input('Email: ');
echo $this->Form->input('Password: ');
echo $this->Form->end('Click here to Register');

?>

编辑 - 我尝试插入数据的表的名称称为 individual 任何帮助将不胜感激

最佳答案

我认为您的代码中的错误位于下面给出的行中。

if($this->request->is('individuals'))

此处$this->request->is 检查请求类型,并且您已在此处分配individuals,但这不是请求类型。请求类型包括 post、'put'、'ajax'、'GET' 等。因此,请检查您表单的方法并将其放入 $this->request->is() 中。请查看这个网址:

http://book.cakephp.org/2.0/en/controllers/request-response.html

关于php - cakePHP 表单不向数据库发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10578117/

相关文章:

php - 正则表达式排除标题标签之间的内容

mysql - 无法创建表(错误号 :121) when importing mysql workbench export dump only on Linux

sql - Postgres 数据库如果不存在则创建

mysql - 使用 Windows 窗体 vb.net 在数据 GridView 中的复选框列的标题中添加一个复选框

php - 如何在PHP中存储cookie以在不登录的情况下唯一标识用户投票

database - 带有数据库的 Laravel 本地化文件

ios - Xcode 管理 "Core data"条记录

php - 无法登录。下面的代码有什么问题?

php - 如何在 Laravel 中通过翻译从多对多关系中仅获取事件元素

PHP MySQL session_set_save_handler 竞争条件