【问题标题】:save value null to database using codeigniter使用 codeigniter 将值 null 保存到数据库
【发布时间】:2019-08-03 22:35:47
【问题描述】:

错误信息 发生数据库错误 错误号:1366

不正确的整数值:第 1 行的列 'parent_id' 的 ''

INSERT INTO cli_request_type (request_type, parent_id, created_on, created_by) VALUES ('Software', '', '2019-03-13 10:35:54', 1)

文件名:C:/Xamppi/htdocs/clihelpdesk/bonfire/core/BF_Model.php

行号:482

我在使用codeIgniter时遇到问题,这种情况是当我想创建parent_id = null的父级时,可以保存到数据库中的只能是一个父级,而当我想用parent_id创建下一个父级时,但总是会引发类似以下整数值的错误通知:'' for column 'parent_id' at row 1"。 我怎样才能让更多的父母不仅仅是一个?

I want to be like this

查看代码

<div class="control-group">
<?php
    $options = array();
    $result = $this->db->count_all_results('request_type');
    if ($result > 0) 
    {
        echo form_dropdown('parent_id', dd2menu('request_type', array('id' => 'request_type')), $options, set_value('parent_id', isset($request_type->request_type) ? $request_type->request_type : 'Parent Id*'));
    }
    else 
    {
        echo form_dropdown('name', dd2menu('request_type', array('id' => 'request_type')), $options, set_value('parent_id', isset($request_type->request_type) ? $request_type->request_type : 'Parent Id*'));
    }                    
?>
</div>

我的控制器

public function create()
{

    $this->auth->restrict($this->permissionCreate);
    $data['reqt'] = $this->db->get('request_type')->result();
    Template::set('request_type');

    if (isset($_POST['save'])) {
        if ($insert_id = $this->save_request_type()) {
            log_activity($this->auth->user_id(), lang('request_type_act_create_record') . ': ' . $insert_id . ' : ' . $this->input->ip_address(), 'request_type');
            Template::set_message(lang('request_type_create_success'), 'success');

            redirect(SITE_AREA . '/settings/request_type');
        }

        // Not validation error
        if ( ! empty($this->request_type_model->error)) {
            Template::set_message(lang('request_type_create_failure') . $this->request_type_model->error, 'error');
        }
    }

    Template::set('toolbar_title', lang('request_type_action_create'));

    Template::render();
}
/**
 * Allows editing of Request Type data.
 *
 * @return void

【问题讨论】:

  • 请始终显示所有错误信息
  • 发生数据库错误错误编号:1366 不正确的整数值:第 1 行的列 'parent_id' 的 '' INSERT INTO cli_request_type (request_type, parent_id, created_on, @987654329 @) VALUES ('Software', '', '2019-03-13 10:35:54', 1) 文件名:C:/Xamppi/htdocs/clihelpdesk/bonfire/core/BF_Model.php 行号:482跨度>
  • 根据您选择的图片请参考此[stackoverflow.com/questions/55003622/…
  • Incorrect integer value 表示您的表期望 parent_id 是一个整数(很可能它具有 INT 的数据类型)。空值(与NULL 值不同)不是整数。如果需要插入空值,则需要在模型中显式插入空值(例如$this-&gt;db-&gt;set('parent_id', null, false);
  • @M.Hemant 这个例子和我做的差不多,subid的值为0,只有一个在花丛中,我有不止一个subid值为的数据0,谢谢:)

标签: javascript php codeigniter


【解决方案1】:

但它可以使空值在整数数据类型中超过一个吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 2014-09-24
    相关资源
    最近更新 更多