Can someone help to get out of this error as i have trapped in this error for a while,It’s became very much frustated for me to get out of this error.
Error is:
Update Blog
A PHP Error was encountered
Severity: Warning
Message: Undefined array key “blog_id”
Filename: blog/editblog.php
Line Number: 8
This is y editblog.php view page
load->view(‘Admin/header’); ?>
Update Blog
” method=”POST”>
Title:
“>
<!-- by this for the form we can populate the data -->
<div class="form-group">
<b><label for="description" class="ms-5">Description:</label></b>
<?php $textarea = array(
'name'=>'desc',
'id' =>'description',
'value'=>set_value('desc',$blog['desc']),
'rows'=>'5',
'cols'=>'5',
'class'=>'form-control mx-5'
);
echo form_textarea($textarea); ?>
<p ><?= form_error('desc');?></p>
</div>
<br>
<div class="form-group">
<b><label for="author" class="ms-5">Author:</label></b>
<input type="text" class="form-control mx-5" name="author" value="<?= set_value('author',$blog['author']);?>" placeholder="Author of the blog">
<p><?= form_error('author');?></p>
</div>
<br>
<button class="btn btn-primary mx-5" name="submit" type="submit">Update</button>
</form>
load->view(‘Admin/footer’); ?>
This is my controller:
public function update_blog($blog_id)
{
$this->load->model('blogmodel');
$dataarr = $this->blogmodel->getdata($blog_id);
$datalist = array();
$datalist['blog'] = $dataarr;
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title of the blog', 'trim|required');
$this->form_validation->set_rules('desc', 'description of the blog', 'trim|required');
$this->form_validation->set_rules('author', 'author of the blog', 'trim|required');
if ($this->form_validation->run() == false) {
$this->load->view('Admin/blog/editblog', $datalist);
} else {
$data = array();
$data['title'] = $this->input->post('title');
$data['desc'] = $this->input->post('desc');
$data['author'] = $this->input->post('author');
$data['created_at'] = date('Y-m-d');
$this->blogmodel->edit($blog_id, $data);
$this->session->set_flashdata('success', 'Blog updated successfully');
redirect('Blog/bloglist');
}
}
Below is my model as blog_model.php
db->insert(‘blogs’,$formArray);
}
//fetching the all blogs records
public function getAllrecords() {
return $blogs = $this->db->get(‘blogs’)->result_array();
}
//updating the blogs
public function edit($blog_id,$data) {
$this->db->where(‘blog_id’,$blog_id);
$this->db->update(‘blogs’,$data);
}
//fetching one record with blogid
public function getdata($blog_id) {
$this->db->where(‘blog_id’,$blog_id);
$result = $this->db->get(‘blogs’)->result_array();
return $result;
}
function delete_blog($blog_id) {
$this->db->where(‘blog_id’,$blog_id);
$this->db->delete(‘blogs’);
}
}
?>