php – 无法将空白发布到数据库:postgreSQL和Codeigniter

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 无法将空白发布到数据库:postgreSQL和Codeigniter脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的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版本以确认这一点.

这里是PHPdocumentation

脚本宝典总结

以上是脚本宝典为你收集整理的php – 无法将空白发布到数据库:postgreSQL和Codeigniter全部内容,希望文章能够帮你解决php – 无法将空白发布到数据库:postgreSQL和Codeigniter所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。