Мой контроллер:
<?php
/**
*
*/
class Product extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
//$this->load->library('session');
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload',$config);
$this->load->model('Pro_model');
}
public function NewProduct(){
$data['categories'] = $this->Pro_model->fetchCat();
$data['upload_error'] = $this->upload->display_errors();
//var_dump($cat_res); exit;
$this->load->view('common/header');
$this->load->view('common/sidebar');
$this->load->view('addnewpro',$data);
$this->load->view('common/footer');
}
public function Pro_insert(){
$this->form_validation->set_rules('proname','Product Name','required');
$this->form_validation->set_rules('prodesc','Product Description','required');
$this->form_validation->set_rules('proprice','Product Price','required');
$this->form_validation->set_rules('procat','Product Category','required');
if ($this->form_validation->run() && $this->upload->do_upload('proimg')) {
$post = $this->input->post();
unset($post['submit']);
//var_dump($post); exit;
$data = $this->upload->data();
$img_path = base_url("upload/".$data['raw_name'].$data['file_ext']);
//var_dump($img_path); exit;
$post['img_path'] = $img_path;
$post_data = $this->Pro_model->insert_product($post);
// var_dump($pro_data); exit;
if ($post_data) {
$this->session->set_flashdata('prosuccess','Product Insert Success');
//redirect('Product/Pro_insert');
$this->NewProduct();
}
else{
$this->NewProduct();
}
}
else{
$this->NewProduct();
}
}
}
Моя модель:
<?php
/**
*
*/
class Pro_model extends CI_Model
{
public function insert_product($post){
return $this->db->insert('product',$post);
//echo $this->db->last_query(); exit;
}
public function fetchCat()
{
$res = $this->db->get('category');
//echo $this->db->last_query(); exit;
return $res->result();
}
}
Мой вид:
<!-- MAIN CONTENT-->
<div class="main-content">
<div class="section__content section__content--p30">
<div class="container-fluid">
<?php
if ($this->session->flashdata('prosuccess')) { ?>
<div class="alert alert-success">
<?php echo $this->session->flashdata('prosuccess'); } ?></div>
<div class="row">
<div class="col-lg-6">
<form action="<?php echo base_url('product/Pro_insert'); ?>" method="post" enctype="multipart/form-data">
<div class="card">
<div class="card-header">
<strong>Add New</strong> Product
</div>
<div class="card-body card-block">
<div class="has-success form-group">
<label for="inputIsValid" class=" form-control-label">Product Name</label>
<input type="text" name="proname" class="is-valid form-control-success form-control">
<div style="color: red"><?php echo form_error('proname'); ?></div>
</div>
<div class="has-warning form-group">
<label for="inputIsInvalid" class=" form-control-label">Product Description</label>
<input type="text" name="prodesc" class="is-invalid form-control">
<div style="color: red"> <?php echo form_error('prodesc'); ?></div>
</div>
<div class="has-warning form-group">
<label for="inputIsInvalid" class=" form-control-label">Product Price</label>
<input type="text" name="proprice" class="is-invalid form-control">
<div style="color: red"> <?php echo form_error('proprice'); ?></div>
</div>
<div class="has-warning form-group">
<label for="inputIsInvalid" class=" form-control-label">Product Category</label>
<select name="procat" class="is-invalid form-control">
<?php
foreach ($categories as $cat) { ?>
<option value="<?php echo $cat->cat_id; ?>"><?php echo $cat->cat_name; ?></option>
<?php } ?>
<div style="color: red"> <?php echo form_error('procat'); ?></div>
</select>
</div>
<div class="has-warning form-group">
<label for="inputIsInvalid" class=" form-control-label">Product Image</label>
<input type="file" name="proimg" class="is-invalid">
<?php if ($upload_error) {
echo $upload_error;
} ?>
</div>
</div>
<div class="card-footer">
<input type="submit" name="submit" class="btn btn-primary btn-sm">
</div>
</div>
</form>
</div>
</div>
Моя ошибка:
Произошла ошибка базы данных Номер ошибки: 1054
Неизвестный столбец «Место» в «списке полей»
INSERT INTO product
(proname
, prodesc
, proprice
,procat
, img_path
) ЗНАЧЕНИЯ ('султан', 'али', '2323', '11', 'http://localhost/shop/Admin/upload/Penguins7.jpg')
Имя файла: G: / xampp / htdocs / shop / Admin / system/database/DB_driver.php
Номер строки: 691