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")
            );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证