gpt4 book ai didi

SQL更新语句中缺少cakephp post数据字段

转载 作者:行者123 更新时间:2023-12-01 14:45:49 25 4
gpt4 key购买 nike

无法让 cakephp 更新记录。

Controller 代码:

public function viewBenefit($id) {
if ($this->request->is('post')) {
$this->set('post', $this->request->data);
$this->Benefit->id = $id;
if ($this->Benefit->save($this->Benefit->data)) {
$myVars['Sucsess'] = TRUE;
$this->Session->setFlash('Updates Saved');
} else {
$myVars['NewID'] = 0;
$myVars['Sucsess'] = False;
$this->Session->setFlash('There was an error.');
}
}

$this->Benefit->recursive = 2;
$this->Benefit->id = $id;
$this->set('benefit', $this->Benefit->read());
}

相关查看代码:

<?php echo $this->Form->create('Benefit',array('action'=>'edit','url' => '#')); ?>
<?php echo $this->Form->input('id',array('type'=>'hidden')) . "\n"; ?>
<?php echo $this->Form->input('short_description',array('type'=>'textarea')) . "\n"; ?>
<?php echo $this->Form->end(); ?>

注意:表单是通过JS提交的

POST 数据(通过 debug($post); )

array(
'Benefit' => array(
'id' => '1952e98e-f589-47d4-b458-11a1bd58ba3b',
'short_description' => '<p>This is great sample insurance 321321</p>'
)
)

SQL 更新语句:

UPDATE `c16memberdev`.`benefits` SET `modified` = '2012-12-04 10:45:16' WHERE `c16memberdev`.`benefits`.`id` = '1952e98e-f589-47d4-b458-11a1bd58ba3b'

如您所见,“short_description”字段未添加到 SQL 语句中,因此数据未添加到数据库中。感谢您的帮助。

最佳答案

尝试改变

$this->Benefit->save($this->Benefit->data)

$this->Benefit->save($this->request->data)

关于SQL更新语句中缺少cakephp post数据字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13708427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com