【问题标题】:Update table row using codeigniter and save it in to database使用 codeigniter 更新表行并将其保存到数据库中
【发布时间】:2016-01-04 10:59:25
【问题描述】:

点击编辑图标填写表单应该打开,并进行更新

控制器代码

    public function update_menus( $id ) {
    $data = array(
        'menu_title' => $this->input->post('menu_title'),
        'filepath' => $this->input->post('filepath'),
        'description' => $this->input->post('description'),
        'left_content' => $this->input->post('left_content'),
        'right_content' => $this->input->post('right_content'),
        'url_path' => $this->input->post('url_path'),
        'created_date' => date('Y-m-d H:i:s')
    );
    if ($this->login_database->update($id, $data) == TRUE) {
        $this->session->set_flashdata('flash_message', 'updated');
    } else {
        $this->session->set_flashdata('flash_message', 'not_updated');
    }
    $this->load->view('update_menus');
    $data = array();
    $data['menus'] = $this->login_database->get_menus_by_id($id);

    $this->load->view('menu_details', $data);
}

型号代码

public function update($id)
{   
    $data = array(

            'menu_title'=> $this->input->post('menu_title'),
            'filepath' => $this->input->post('filepath'),
            'description' => $this->input->post('description'),
            'left_content' => $this->input->post('left_content'),
            'right_content' => $this->input->post('right_content'),
            'url_path' => $this->input->post('url_path'),
            'created_date' =>date('Y-m-d H:i:s')
            );
    $this->db->where('id',$id);
    $menus = $this->db->update('menu_details', $data);
    return $menus->result();
}

查看代码

     <?php
echo form_open('user_authentication/update_menu_submit');
?><?php foreach ($menus->result() as $row) {
    ?>
    <div class="box-body">

        <div class="form-group">
            <label for="exampleInputEmail1">Menu Title</label>
            <input type="text" name="menu_title" class="form-control" id="exampleInputTitle" placeholder="Enter Menu Title">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Menu Url</label>
            <input type="text" name="url_path" class="form-control" id="exampleInputurl" placeholder="Enter File Path">
        </div>
        <div class="form-group">
            <label for="exampleInputFile">Upload Image</label>
            <input type="file" name="filepath" id="exampleInputFile">
        </div>
        <div class="form-group">
            <label for="exampleInputDesc">Description</label>
            <textarea id="editor4" name="description"  rows="10" cols="80" placeholder="Enter Description"></textarea>
        </div>
        <div class="form-group">
            <label for="exampleInputcontl">Left Content</label>
            <textarea id="editor5" name="left_content"  rows="10" cols="80" placeholder="Enter Left Content"></textarea>
        </div>
        <div class="form-group">
            <label for="exampleInputcontr">Right Content</label>
            <textarea id="editor3" name="right_content"  rows="10" cols="80" placeholder="Enter Right Content"></textarea>
        </div>
        <div class="box-footer">
            <button type="submit" class="btn btn-primary">Submit</button>
        </div>
    </div>
    <?php
}
echo form_close();
?>
</div>

一旦点击编辑操作,它应该重定向到查看页面并应该打开填写的表单,它显示错误

致命错误:在布尔值中调用成员函数 result() C:\xampp\htdocs\codecms\application\models\login_database.php 上线 型号代码中的205,

【问题讨论】:

  • 请先在此处重新格式化您的帖子以使其可读,我还建议突出显示模型中的指定行以使其更易于调试。

标签: php mysql codeigniter


【解决方案1】:

您可以使用以下命令检查生成的查询吗: $this- db- last_query();

$data = array(

        'menu_title'=> $this->input->post('menu_title'),
        'filepath' => $this->input->post('filepath'),
        'description' => $this->input->post('description'),
        'left_content' => $this->input->post('left_content'),
        'right_content' => $this->input->post('right_content'),
        'url_path' => $this->input->post('url_path'),
        'created_date' =>date('Y-m-d H:i:s')
        );
$this->db->where('id',$id);
$menus = $this->db->update('menu_details', $data);
$this->db->last_query();

在您的 php 管理员中检查生成的查询。

返回 $menus->result();需要吗?

【讨论】:

  • 致命错误:第 206 行 C:\xampp\htdocs\codecms\application\models\login_database.php 中的布尔值调用成员函数 result()
  • return $menus->result(); ,在上面的这一行中显示错误。
  • 第 206 行的 login_database.php 中有什么内容?
  • 评论一下试试
  • 遇到 PHP 错误 严重性:通知消息:未定义变量:菜单文件名:views/update_menus.php 行号:67 致命错误:在 C:\ 中调用 null 上的成员函数 result()
猜你喜欢
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
  • 1970-01-01
相关资源
最近更新 更多