如何使用codeigniter将选项值插入数据库

时间:2016-06-04 03:27:37

标签: php mysql codeigniter

我需要使用此选项视图将我的选项值插入数据库:

<label>Add Time</label>:
<select id="dropdownHolder" name="restaurant_busy">
    <option value="1">30 minute</option>
    <option value="2">1 hour</option>
    <option value="3">1 hour 30minute</option>
    <option value="4">2 hour</option>
</select>

这是控制器我所做的:

function change_restaurant(){
    if(!isset($_COOKIE["vendor_login"])){ redirect("/VENDOR",'refresh'); }
    if(!$this->Token_m->m_check_token($this->input->cookie('vendor_login'),$this->input->cookie('vendor_token'))){
        setcookie('vendor_login', '', time() - 3600, '/');
        redirect('/VENDOR/',"refresh");
    }
    if ($this->input->cookie('vendor_login') != null) {
        $admin_name = $this->input->cookie('vendor_login');

        setcookie('vendor_login', $admin_name, time() + 28800, '/');
        $msg = $this->input->cookie('vendor_token');
        setcookie('vendor_token', $msg, time() + 28800, '/');
    }
    if($vendorname = $_COOKIE["vendor_login"]) {
        $check_login = $this->Vendor_m->m_get_user_by_vendor($vendorname);
        $restaurant_id = $check_login["restaurant_id"];
        {
            if ($_POST = NULL){
                redirect("/VENDOR/Vendor/restaurant_setting","refresh");
            }
            $data = array(
            "restaurant_info"=>$this->input->post("restaurant_info"),
            'restaurant_busy' => $this->input->post("restaurant_busy")
            );
            $this->Vendor_m->m_update_restaurant_info( $data,$restaurant_id);
            $this->db->last_query();
        }
    }redirect("/VENDOR/Vendor/restaurant_setting","refresh");
}

这个模型:

function m_update_restaurant_info($restaurant_info, $restaurant_id)
{
    $this->db->where("restaurant_id", $restaurant_id);
    $this->db->update("uhd_restaurant", $restaurant_info);
}

它是我的选项值,在我的数据库中有一个表名&#34; uhd_restaurant&#34;并且字段是&#34; restaurant_busy&#34;,在restaurant_busy中有一些评论如:0 =没有忙(默认),1 = 30分钟,2 = 1小时,3 = 1小时30分钟,4 = 2小时。

如果我选择30分钟,在restaurant_busy必须为1,我应该在控制器和模型中做什么?

在我提交之后我得到以下错误:

  

发生数据库错误

     

错误号码:1054

     

未知栏&#39; restaurant_info&#39;在&#39;字段列表&#39;

     

UPDATE uhd_restaurant SET restaurant_info = NULL,   restaurant_busy = NULL WHERE restaurant_id =&#39; 250&#39;

     

文件名:   C:/Data_web/food.km/application/models/VENDOR/SG/Vendor_m.php

     

行号:554

1 个答案:

答案 0 :(得分:0)

尝试使用单引号。 我想以下行

$data = array(
        "restaurant_info"=>$this->input->post("restaurant_info"),
        'restaurant_busy' => $this->input->post("restaurant_busy")
        );

应该是

$data = array(
        'restaurant_info' =>$this->input->post("restaurant_info"),
        'restaurant_busy' => $this->input->post("restaurant_busy")
        );