BLOG FORM
Database: blog
Table: blog
title
This is The New Blog
This is The New Blog2
content
Vestibulum dolor dolor, bibendum nec iaculis quis,...
Lorem ipsum dolor sit amet, consectetur adipiscing...
date
2016-04-15 00:00:00
2016-04-08 00:00:00
http://localhost/blog/
Can anyone help me fix the code so that it could capture :
Upload : [ browse ]
Title : Title
Content : Content
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');
}
}
?>
models/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."