Hi
This is a long shot because I'm not sure if you guys help with web development,
I'm trying to insert images and text into a database, I have found tutorials which show you how to insert but they only give you one item, for example the tutorial will have only on how to insert images into a database.
this is my controller
<?php
class Bras extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('bras_model');
$this->load->helper('url');
$this->load->helper('form');
}
function index() {
$data['title'] = "Voluptuous Decadents";
$data['heading'] = "Bras";
$data['query'] = $this->db->get('bras');
$this->load->view('layout');
$this->load->view('bras/create', $data);
}
function bras_view(){
$data['title'] = "Voluptuous Decadents";
$data['heading'] = "Bras";
$this->db->where('slug', $this->uri->segment(3));
$data['query'] = $this->db->get('bras');
$this->load->view('layout');
$this->load->view('bras/bras_view', $data);
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Create a bra item';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('content', 'content', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('bras/create');
$this->load->view('templates/footer');
}
else
{
$this->bras_model->set_bras();
$this->load->view('bras/success');
}
}
function do_upload() {
$config = array(
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '100',
'max_width' => '1024',
'max_height' => '768',
'encrypt_name' => true,
);
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('bras/create', $error);
} else {
$upload_data = $this->upload->data();
$data_ary = array(
'file' => $upload_data['file_name'],
);
$this->load->database();
$this->db->insert('bras', $data_ary);
$data = array('upload_data' => $upload_data);
$this->load->view('bras/success', $data);
}
}
}
?>
this is my model
<?php
class Bras_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_bras()
{
$query = $this->db->get('bras');
}
public function set_bras()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'content' => $this->input->post('content'),
'file' => $this->input->post('file_name'),
'price' => $this->input->post('price'),
);
return $this->db->insert('bras', $data);
}
}
?>
and this is my view
<h2>Create a bra item</h2>
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('bras/create') ?>
<label for="title">Title</label>
<input type="input" name="title" /><br />
</form>
<?php echo form_open_multipart('bras/do_upload') ?>
<input type="file" name="userfile" size="20" /><br />
</form>
<?php echo form_open_multipart('bras/create') ?>
<label for="content">content</label>
<textarea name="content"></textarea><br />
<label for="price">Price</label>
<input type="input" name="price" /><br />
<input type="submit" name="submit" value="Create Bra item" />
</form>
I really hope you guys can help me