簡體   English   中英

在行代碼更新錯誤時更新行

[英]update rows on codeigniter error

我正在執行此編輯功能,並且不編輯任何內容。 我是這個東西的新手。 我正在獲取正在編輯的值,但無法更新或保存它。 如果無法更新數據庫,但我也將其重定向到編輯視圖,但出現此錯誤,消息:試圖獲取非對象的屬性

文件名:views / edit_view.php

行號:15`

這是代碼。

控制者

///編輯

public function update(){

    $data['content'] = $this->Provinces_Model->getrow();
    $data['content_view'] = 'Provinces/edit_view';
    $this->templates->admin_template($data);

}

public function update_row(){

    if($this->Provinces_Model->update()){
        redirect('Provinces/index');
    }else{
        $this->update();
    }

}

模型

////編輯

public function getrow(){

    $this->db->where('PROV_ID', $this->uri->segment(3));
    $query = $this->db->get($this->table);
    return $query->row();

}

public function update(){

    $id = $this->input->post('PROV_ID');
    $input = array(
            'PROVINCE' => $this->input->post('PROVINCE')
            );

    $this->db->where('PROV_ID', $this->uri->segment(3));
    $update = $this->db->update($this->table, $input);

}

閱讀視圖

        <td><?php echo anchor("Provinces/update/$i->PROV_ID","<i class='fa  fa-edit'>" ); ?></td>

edit view

<div>
    <center>
        <fieldset>


                <?php

                    echo form_open('Provinces/update_row');
                ?>

                <p>
                    <label class="field" for="PROVINCE"><span>*</span>Province Name:</label>
                    <input type = "text" name="PROVINCE" class ="textbox-300" value= "<?php echo $content->PROVINCE; ?>">
                    <label class = "error"><?php echo form_error("PROVINCE"); ?></label>
                </p>

                <?php
                    echo form_submit('submit','Update');
                    echo form_close();
                ?>


        </fieldset>
    </center>
</div>

當我調用update_row()時,我的URL變為localhost / foldername / classname / update_row,如您所見, $this->uri->segment(3)變為null。 我所做的是我已經編輯了edit_view。

            <?php

                $data = $content->PROV_ID;
                echo form_open('Provinces/update_row/'.$data);

            ?>

我將。$ data放在末尾,以便url變為localhost/foldername/classname/update_row/valueof$data

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM