drwn65609 2016-06-04 03:27
浏览 34
已采纳

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

i need to insert my option value into database with this option view :

<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>

this the controller what i have done :

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");
}

this the model :

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

that its my option value, in my database there is a table name "uhd_restaurant" and the field is "restaurant_busy", in restaurant_busy there are some comments like : 0=no busy(as default), 1=30 minute, 2=1 hour, 3=1 hour 30 minute, 4= 2 hour.

if i select 30minute, in restaurant_busy must be 1, what should i do in controller and in model?

and after i submit it i got this following error :

A Database Error Occurred

Error Number: 1054

Unknown column 'restaurant_info' in 'field list'

UPDATE uhd_restaurant SET restaurant_info = NULL, restaurant_busy = NULL WHERE restaurant_id = '250'

Filename: C:/Data_web/food.km/application/models/VENDOR/SG/Vendor_m.php

Line Number: 554

  • 写回答

1条回答 默认 最新

  • dongzhang1864 2016-06-04 11:40
    关注

    Try with single quotes. I think following line

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

    should be

    $data = array(
            'restaurant_info' =>$this->input->post("restaurant_info"),
            'restaurant_busy' => $this->input->post("restaurant_busy")
            );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)