Hi all,
Using CodeIgniter to write to a database using a form, but am a bit stuck. Think it's just of case of what to a form action part of my form.php page but could be more issues. Any ideas? Code below.
book_controller.php
<?php
class Book_controller extends CI_Controller
{
function index()
{
$this->load->view('form.php');// loading form view
}
function insert_to_db()
{
$this->load->model('book_model');
$this->load->view('success');//loading success view
}
}
?>
book_model.php
<?php
class Book_model extends CI_Model
{
function insert_into_db()
{
$title = $_POST['title'];
$author = $_POST['author'];
$publisher = $_POST['publisher'];
$this->db->query("INSERT INTO books VALUES('$title','$author','$publisher')");
}
}
?>
form.php
<h1>Book form</h1>
<form action="<?php ?>" method="post">
Title = <input type = 'text' name='title'>
Author = <input type = 'text' name='author'>
Publisher = <input type = 'text' name='publisher'>
<input type='submit'>
</form>