BLOG FORM
Date: I I I I
Upload: Image
Title: Title
Content: Content
Hello,
Can anyone help me fix the code so that whenever someone input in the views/blog_form.php
Upload: [ upload ]
Title: [ title ]
Content: [ content ]
It truely place and move the code to the database through model. Can anyone help me to fix it?
views/blog_form.php
PHP Code:
<html>
<title>Blog Form</title>
<br>
<h1>BLOG FORM</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('blog'); ?>
<table>
<tr>
<td>Date :</td>
<td><?php echo $this->calendar->generate(); ?></td>
</tr>
<tr>
<td>Upload :<br><br></td>
<td><input type="file" name="pic" id="pic"><br></td>
</tr>
<tr>
<td>Title :</td>
<td><input type="text" name="username" value="" size="30" /></td>
</tr>
<tr>
<td>Content :</td>
<td>
<textarea rows="8" cols="40">
</textarea>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</form>
</table>
</html>
controllers/blog.php
PHP Code:
<?php
class Blog extends CI_Controller {
// If you want code to run for every method in a controller, you need to create a constructor
public function __construct()
{
parent::__construct();
$this->load->helper('date');
$this->load->helper('form');
$this->load->library('calendar');
$this->load->library('form_validation');
$this->load->model('blog_model');
}
public function index()
{
$data['title'] = $this->blog_model->select_blog();
$data['content'] = $this->blog_model->select_blog();
$data['date'] = $this->blog_model->select_blog();
$this->load->view('blog', $data);
}
public function blog_form()
{
$this->load->view('blog_form');
}
}
?>
model/blog_model.php
PHP Code:
<?php
class Blog_model extends CI_Model {
public $title;
public $content;
public $date;
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
$this->load->database();
}
public function select_blog()
{
$query = $this->db->query('SELECT * FROM blog');
return $query->result();
// return 'masuk loh';
}
public function insert_blog()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('blog', $this);
}
public function update_blog()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('blog', $this, array('id' => $_POST['id']));
}
}
?>
" If I looks more intelligence please increase my reputation."