ErrorException[注意]:数组到字符串转换PHP表单
我正在创建一个非常简单的表单,用于从用户收集数据并存储在数据库中,但我遇到了一个错误: ErrorException[注意]:数组到字符串的转换 SYSPATH\classes\kohana\html.php 我以前在我的另一个表单中使用过这个代码,我从来没有遇到过任何问题,也许我遗漏了什么ErrorException[注意]:数组到字符串转换PHP表单,php,database,forms,kohana,Php,Database,Forms,Kohana,我正在创建一个非常简单的表单,用于从用户收集数据并存储在数据库中,但我遇到了一个错误: ErrorException[注意]:数组到字符串的转换 SYSPATH\classes\kohana\html.php 我以前在我的另一个表单中使用过这个代码,我从来没有遇到过任何问题,也许我遗漏了什么 <div id="formWrapper"> <?php { echo form::open('', array('id'=>'newprefecture'));
<div id="formWrapper">
<?php
{
echo form::open('', array('id'=>'newprefecture'));
echo form::label('NewPrefecture', 'prefecture:');
echo form::input('form[NewPrefecture]', array('class'=>'input', 'id'=>'NewPrefecture'));
echo form::submit('btnSubmit', 'Submit', array('id'=>'btnSubmit', 'class'=>'button'));
echo form::close();
}
?>
</div>
public function action_newprefecture(){
$this->template->content = View::factory('admin/main-menu');
$this->template->content->val = '';
$this->template->content->post = '';
if ($this->request->post('form')) {
$post = $this->request->post('form');
$stmt = DB::query(Database::INSERT, 'INSERT INTO `prefectures` (`prefecture`)
VALUES (:NewPrefecture)');
$stmt->param(':NewPrefecture', $post['NewPrefecture']);
try {
$stmt->execute();
$this->template->content->post = $post;
$this->template->content->thanks = true;
} catch (Exception $e) {
FB::error($e);
}
}
}
公共职能行动(){
$this->template->content=View::factory('admin/main menu');
$this->template->content->val='';
$this->template->content->post='';
如果($this->request->post('form')){
$post=$this->request->post('form');
$stmt=DB::query(数据库::INSERT,'INSERT INTO'perfectures`('perfectures`)
值(:newaperty);
$stmt->param(':newaperties',$post['newaperties']);
试一试{
$stmt->execute();
$this->template->content->post=$post;
$this->template->content->thank=true;
}捕获(例外$e){
FB::错误($e);
}
}
}
看起来您可能需要在属性之前为输入添加一个默认值(或NULL),如下所示:
echo form::input('form[NewPrefecture]', NULL, array('class'=>'input', 'id'=>'NewPrefecture'));
错误应该指向代码中的特定行-是哪一行?1)这不是错误,而是通知,它只是意味着将数组传递给一个函数,该函数尝试
将该数组作为字符串回显。2) 正确缩进/格式化代码3)添加通知中的行号4)无论何时何地都避免使用静态方法第66行-返回htmlspecialchars((字符串)$value,ENT_引号,Kohana::$charset,$double_encode);