php – 无法将空白发布到数据库:postgreSQL和Codeigniter
发布时间:2020-12-13 22:51:44 所属栏目:PHP教程 来源:网络整理
导读:在我的View页面中,我有一个空白输入,但每当我必须发布到我的数据库时,它会出错. 查看页面: label for="column1"COLUMN1:/label input type="input" name="column1" 型号页面: 'column1' = $this-input-post('column1'), 如果输入为空,则此代码不会满足.如
在我的View页面中,我有一个空白输入,但每当我必须发布到我的数据库时,它会出错.
查看页面: <label for="column1">COLUMN1:</label> <input type="input" name="column1"> 型号页面: 'column1' => $this->input->post('column1'), 如果输入为空,则此代码不会满足.如何将其发布到我的数据库,其值为0而不是空白(因为它不会令人满意). Column1是一个整数类型,所以空白值不是我理解的整数.谁能帮我. 顺便说一下,我正在使用Codeigniter和PostgreSQL 编辑——-我的真实代码 模型 public function changeNow_table2_A(){ $seq = $this->input->post('seq'); $data = array( 'tech_voc' => $this->input->post('tech_voc'),'bacc' => $this->input->post('bacc'),'post_bacc' => $this->input->post('post_bacc'),'llb' => $this->input->post('llb'),'md' => $this->input->post('md') ); $this->db->where('seq',$seq); $this->db->update('table2',$data); } // this work 我试过改变了 'bacc' => empty($this->input->post('bacc'))? 0 : $this->input->post('bacc'),// changing 'bacc' to this,it gets server error. 解决方法
不确定你是否解决了这个问题 – 以防万一,这是另一个答案.
$column1 = $this->input->post('column1'); $data = array('testcol' => 'testing','column1' => (empty($column1) || !is_numeric($column1)) ? 0 : $column1); 如果column1为空或者column1不是数字,则将column1设置为0 在5.5版之前,空函数仅支持变量.含义为空($this-> input-> post(‘field’))会抛出致命错误. PHP 5.5包括支持使用表达式作为空的参数.该错误很可能是使用函数作为空函数的参数的结果.检查你的PHP版本以确认这一点. 这里是php空documentation (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |