mysql - Codeigniter 中的更新状态列不起作用

标签 mysql codeigniter

大家好,我正在尝试将表的状态列contentdetails更新为0。我不知道确切的问题是什么以及我在哪里犯了错误,我无法更新我的状态栏。

这是我的 Controller :

function deleteImage() {
    // Pass the $id to the contentDelete() method
    $id = $this->input->post('image_id');
    if ($id) {
        $this->Content_model->imageDelete($id);
        $this->session->set_flashdata('success', 'Image deleted.');
        redirect('Content');
    } else {
        $this->session->set_flashdata('error', 'Image Id not captured.');
        redirect('Content');
    }
}

这是我的模型:

function imageDelete($id) {
    $this->db->set('status', 0); //value that used to update column  
    $this->db->where('id', $id); //which row want to upgrade  
    $this->db->update('contentdetails');  //table name
}

这是我的观点:

<table class="table table-striped table-bordered" id="dataTable1">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Image path</th>
                            <th class='text-center'>Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($bgimglist as $bgimgs) {
                            ?>
                            <tr>
                                <td><?php echo $bgimgs->id; ?></td> 
                                <td><?php echo $bgimgs->details; ?></td> 
                                <td class='text-center'>
                                     <form method="post" action="<?php echo base_url('Content/deleteImage'); ?>">
                                             <input type="text" name="image_id" value="<?php echo $bgimgs->id; ?>">
                                            <button type="submit" onclick="return ConfirmDelete()" class="btn btn-danger btn-xs confirmation" name="login"><i class='fas fa-times'></i></button>
                                        </form>
                                </td>
                            </tr>
                            <?php
                        }
                        ?> 
                    </tbody>
                </table>

谁能帮我解决我做错的地方。

提前致谢。

最佳答案

由于一些误解OP,虽然form_open()还用上述评论中讨论中可用的代码关闭了表单。因此,任何进一步的表单调用都将转到从未关闭的表单。

添加 </form>开放形式解决了这个问题。

关于mysql - Codeigniter 中的更新状态列不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51606343/

相关文章:

mysql - 将数据库架构与 MySQL Workbench 进行比较

MySql 将日期存储为 Date 或 BigInt (Epoch)

php - MySQL:如何从包含 2 个用户显示的 'expenses' 表中显示 2 个 u_name(从 'users' 表中拉出 2 个不同的行)?

javascript - 如何在 JQuery 中重复相同的代码,并为每个代码附加不同的编号?

php - 如何从 Controller 返回的查询中获取数据

php - 多维数组转json

php - 将 HTML 表格单元格值插入 MySQL

mysql - 如何通过mysql对group进行嵌套选择

codeigniter - 在 CodeIgniter 中将数据导出为 CSV

php - 如何使用带有数据库中的值的复选框,其中数据库中的类型列(设置)codeigniter