Ich habe ein Formular, Textfelder und einzelnes Bild haben, fügen das Textfeld in die Datenbank erfolgreich ein, aber Bildpfad fügt nicht in der Datenbank, die ich in Bildvariable gespeichert habe, ich benutze MySQL-Datenbank, das Bild wird in den Ordner hochgeladen, aber der Pfad wird nicht in der Datenbank gespeichert.Einfügen von Bild Pfad zur Datenbank in Codezeichner
Die Controller-Datei
class product{
function validate_products()
{
$this->form_validation->set_rules('title', 'title', 'trim|required|');
$this->form_validation->set_rules('price', 'price', 'trim|required');
$this->form_validation->set_rules('description', 'description', 'trim|required');
$this->form_validation->set_rules('category', 'category', 'trim|required');
//$this->form_validation->set_rules('image', 'image', 'trim|required');
$config = array(
'upload_path' => "./images/",
'allowed_types' => "gif|jpg|png|jpeg",
'overwrite' => false,
);
$this->load->library('upload', $config);
if($this->form_validation->run() && $this->upload->do_upload())
{
$data = $this->upload->data();
$image= base_url("images/". $data['raw_name'] . $data['file_ext']);
$post['image'] = $image;
$this->load->model('upload_model');
if($query= $this->upload_model->create_product())
{
$this->session->set_flashdata('product_sucsess', 'Product uploaded sucsessfully');
$this->upload();
}
else
{
$this->session->set_flashdata('product_fail', 'Sorry product not uploaded .');
$this->load->view('Admin/upload_product');
}
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/upload_product', $error);
}
}
}
Die Modellklasse
class upload_model extends CI_Model
{
\t public function __construct()
{
parent::__construct();
$this->load->database();
}
\t
\t
\t function create_product()
\t {
\t \t $new_member_insert_data = array(
\t \t 'title'=> $this->input->post('title'),
\t \t 'image'=> $this->input->post('image'),
\t \t 'price'=> $this->input->post('price'),
\t \t 'description'=> $this->input->post('description'),
\t \t 'category'=> $this->input->post('category'));
\t \t
\t \t $insert = $this->db->insert('product', $new_member_insert_data);
\t \t return true;
\t }
\t
}
Dank einer Tonne kimberlee es funktioniert – Raahull