简体   繁体   中英

update rows on codeigniter error

i am making this edit function and its not editing anything. i am new to this thing. i am getting the value of the that i am editing but i cannot update it or save it. also i am redirecting this one to the edit view if it fails to update database but i got this error, `Message: Trying to get property of non-object

Filename: views/edit_view.php

Line Number: 15`

here is the codes.

controller

/// EDIT

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();
    }

}

model

//// EDIT

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);

}

read view

        <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>

when i call the update_row() my url becomes localhost/foldername/classname/update_row so as you can see, $this->uri->segment(3) becomes null. what i did is i have edited the edit_view..

            <?php

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

            ?>

i put .$data at the end so that the url will become localhost/foldername/classname/update_row/valueof$data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM