While learning how to use Code Igniter, i have encountered a problem when submitting form values. I'm trying to do an insert if $_POST and redirect to the form if it wasn't successful, but every time i submit the form i see there are no form values in my header. Been unable to figure out what am doing wrong even after going through several related post, would appreciate the help of the experts here. Here's what I'm working with
View: new_product.php
<form action="products/new_product" method="POST" role="form">
<legend>Upload New Item</legend>
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" id="name" placeholder="Input field">
<label for="">Description</label>
<input type="text" class="form-control" id="description" placeholder="Input field">
<label for="">Category</label>
<input type="text" class="form-control" id="category" placeholder="Input field">
<label for="">Price</label>
<input type="text" class="form-control" id="price" placeholder="Input field">
</div>
<button type="submit" class="btn btn-primary">Upload</button>
</form>
Controller: products.php
public function new_product()
{
if ($_POST) {
$data = array(
'category' => $this->input->post('category'),
'name' => $this->input->post('name'),
//'photo' => $this->input->post('photo'),
'description' => $this->input->post('description'),
'price' => $this->input->post('price')
);
$this->product->upload_product($data);
redirect(base_url().'products/');
} else {
$this->load->view('header', FALSE);
$this->load->view('new_product');
$this->load->view('footer', FALSE);
}
}
Model: product.php
function upload_product($data) {
$this->db->insert('products', $data);
return $this->db->insert_id();
}
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
header recorder during form submission
