This is my html code. I want to pass "$category_edit->c_name" value to my Update() controller. I am getting "$category_edit" variable from another controller.
I am using CodeIgniter framework.
<form method="post" action="<?php echo base_url('admin/category/update');?>">
<label>Parent Category: </label></br>
<select name="parent_id">
<?php
echo '<option value="' .$category_edit->id .'">';
echo $category_edit->p_name;
echo '</option>';
?>
</select>
<label>Category</label>
<input type="text" name="<?php echo $category_edit->c_name; ?>" id="category_name" value="<?php echo $category_edit->c_name; ?>">
<button>Update</button>
</form>
This is my update() controller.
I am getting Error:
Trying to get property of non-object
public function update(){
$this->load->model('category_model');
echo $category_edit->c_name;
}
Please kindly check this reference code:
public function update_view()
{
$this->load->model('category_model');
$data['category_edit'] = $this->category_model->get_category_values(); // return array
$data['extra_variable'] = 'lorem ipsum';
$this->load->view('category/update_view', $data);
}
at your category/update_view.php :
<form method="post" action="<?php echo base_url('admin/category/update');?>">
<label>Parent Category: </label></br>
<select name="parent_id">
<?php
echo '<option value="' .$category_edit['id'] .'">';
echo $category_edit['p_name'];
echo '</option>';
?>
</select>
<label>Category</label>
<input type="text" name="<?php echo $category_edit['c_name']; ?>" id="category_name" value="<?php echo $category_edit['c_name']; ?>">
<button>Update</button>
</form>
EDIT:
Please refer: http://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view
Make some changes in HTML(See below code)
<input type="text" name="category_name" id="category_name" value="<?php echo $category_edit->c_name; ?>">
public function update()
{
$this->load->model('category_model');
echo $this->input->post('category_name');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With