Click here to Skip to main content
15,742,323 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
 <?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
Posted

1 solution

There's lots of web devs here. Tagging your question properly would help. this is PHP ?

I don't see any DB code, but inserting an image is always the hard part, inserting the metadata is trivial, because it's just normal SQL. You need to perhaps explain exactly where you're stuck, and post the relevant code. I can't see how the code you posted is relevant to what you asked. If you post a LOT of code, also point out the line that you're stuck on.
 
Share this answer
 
Comments
Kenneth Haugland 31-Jul-12 18:33pm    
From OP:
yes it's php and I'm not sure where the problem is. This is the first time I'm doing web development and I'm using the codeigniter framework. And I can't add both the image and the text at the same time.
Christian Graus 31-Jul-12 19:37pm    
Why are you doing PHP then ? PHP sucks. You should have tagged this PHP ( although then I'd never have looked ). There is no code I see here that does a DB call, unless it's calling some magic framework thing I don't know. Your post is too broad to be useful, and just not clear. It sounds like what you're saying is, you need a copy and paste solution that does EVERYTHING for you as you don't understand your own code. That does not exist.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900