codeigniter中的错误更新行

时间:2013-08-24 20:37:44

标签: codeigniter

我将行更新到数据库时出错。

我的问题是没有更新行并在我上传pic时更新文件上传未在索引中定义。

我的控制员:

public function addedit(){

    $events = new events_model();
    $prodID = $this->input->post('hID');
    $text = $this->input->post('ev_text');
    $pic = $this->do_upload('ev_pic');
    $submit = $this->input->post('submit');

    if($submit){

        if(!empty($prodID)){

            $this->data['events'] = $events->UpdatePost($prodID, $text , $pic );
            $this->data['pagetitle'] = "Show Info";             
            $this->data['success']= "Update Done";

        }else{

            $this->data['success'] = "Add Done";
        }

    $this->data['status'] = "1";

    }else{

        $this->data['status'] = "0";
        $this->data['errors'] = "Error";
    }

    $this->template->build('admin/events/add',$this->data);
}

和型号:

function UpdatePost($prodID, $text , $pic ) {

    if ($pic == ""){

        $vales = array('ev_id' => $prodID , 'ev_text' => $text);

    }else{

        $vales = array('ev_id' => $prodID , 'ev_text' => $text , 'ev_pic' => $pic);
    }

    $query = $this->db->update($this->table_name, $vales) or die (mysql_error());
    $result = array();
    $result["process"] = "ok";
    echo "1";       
}

并查看:

<div class="widget-body">

            <table class="data-table" action="./administrator/categories/delete/"><!-- Table Conversion: See Section E in custom.js -->
                <thead>
                    <tr>
                        <th class="sorting no-background" rowspan="1" colspan="1" style="width: 35px;"><input type="checkbox" id="checkall" /></th>
                        <th class="sorting" rowspan="1" colspan="1" style="width: 343px;">Tittle</th>
                        <th class="sorting" rowspan="1" colspan="1" style="width: 100px;">Date</th>
                        <th class="sorting no-background" rowspan="1" colspan="1" style="width: 70px;">#</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $ctr = 0; ?>
                    <?php foreach ($events as $n): ?>
                            <tr>
                                <td><input class="checkrow" type="checkbox" value="<?php echo $n->ev_id; ?>" /></td>
                                <td class=" sorting_1"><?= $n->ev_text; ?></td>
                                <td class="center"><?= $n->ev_date; ?></td>
                                <td>
                                    <a href="<?php echo $this->page_url; ?>/edit/<?php echo $n->ev_id; ?>" class="ico-btn ico-text-edit" title="Edit"><span>Edit</span></a>
                                    <a href="<?php echo $this->page_url; ?>/delete/<?php echo $n->ev_id; ?>" itemID="<?= $n->ev_id ?>" class="ico-btn ico-text-trash opener-delete" title="Del"><span>Del</span></a>
                                </td>
                            </tr>
                    <?php endforeach ?>
                </tbody>

            </table>



            <div class="clear"></div>
        </div>
         <div class="clear"></div>
    </div>

    <div id="table-extra">
        <div id="table-action">
            <input action="./administrator/<?php echo $this->uri->segment(2)."/deleteitems" ?>" class="btn-theme table-button btn-hover-black DeleteItems" id="submit" type="button" value="Delete" />
        </div>
        <div class="paginate">
            <ul>
                <?= $this->pagination->create_links(); ?>
            </ul>
            <div class="clear"></div>
        </div>

        <div class="clear"></div>
    </div>
</div>
</div>

我的代码中的问题,我不会更新成功。

1 个答案:

答案 0 :(得分:1)

你没有在CI中加载像$events = new events_model();这样的模型,你应该这样做:

$this->load->model('Model_name');

$this->Model_name->function();

参考:http://ellislab.com/codeigniter/user-guide/general/models.html#loading

相关问题