如何使用Opencart在数据库中插入自定义数据

时间:2017-05-02 08:13:10

标签: insert opencart

使用 Opencart 创建我的商店。这里创建了一个名为sales_performance的自定义页面。

我试图在database中插入一些值。

但我无法插入数据,我该怎么做?。

而且它没有显示error

关注我的代码:

控制器 的 sales_performance.php

<?php
class ControllerProductSalesPerformance extends Controller
{
    private $error = array();
    private $data = array();

    public function index()
    {
        $this->load->language('product/allproduct');

        $this->document->setTitle($this->language->get('Sales Performance'));

        $this->load->model('catalog/allproduct');



        $data['action']=$this->url->link('product/sales_performance','','SSL');

        $this->data['text_list'] = $this->language->get('text_list');
        $this->data['text_no_results'] = $this->language->get('text_no_results');
        $this->data['text_confirm'] = $this->language->get('text_confirm');
        $this->data['text_missing'] = $this->language->get('text_missing');

        $this->data['column_order_id'] = $this->language->get('column_order_id');
        $this->data['column_customer'] = $this->language->get('column_customer');
        $this->data['column_status'] = $this->language->get('column_status');
        $this->data['column_total'] = $this->language->get('column_total');
        $this->data['column_date_added'] = $this->language->get('column_date_added');
        $this->data['column_date_modified'] = $this->language->get('column_date_modified');
        $this->data['column_action'] = $this->language->get('column_action');

        $this->data['entry_return_id'] = $this->language->get('entry_return_id');
        $this->data['entry_order_id'] = $this->language->get('entry_order_id');
        $this->data['entry_customer'] = $this->language->get('entry_customer');
        $this->data['entry_order_status'] = $this->language->get('entry_order_status');
        $this->data['entry_total'] = $this->language->get('entry_total');
        $this->data['entry_date_added'] = $this->language->get('entry_date_added');
        $this->data['entry_date_modified'] = $this->language->get('entry_date_modified');

        $this->data['button_invoice_print'] = $this->language->get('button_invoice_print');
        $this->data['button_shipping_print'] = $this->language->get('button_shipping_print');
        $this->data['button_add'] = $this->language->get('button_add');
        $this->data['button_edit'] = $this->language->get('button_edit');
        $this->data['button_delete'] = $this->language->get('button_delete');
        $this->data['button_filter'] = $this->language->get('button_filter');
        $this->data['button_view'] = $this->language->get('button_view');



        //$data['token'] = $this->session->data['token'];



        $pagination = new Pagination();
        //$pagination->total = $order_total;
        //$pagination->page = $page;

        $data['pagination'] = $pagination->render();

        $this->data['sort'] = $sort;
        $this->data['order'] = $order;

        $this->data['header'] = $this->load->controller('common/header');
        $this->data['column_left'] = $this->load->controller('common/column_left');
        $this->data['footer'] = $this->load->controller('common/footer');

        $this->response->setOutput($this->load->view('default/template/product/sales_performance.tpl', $this->data));

    }

    public function insertSelectedCustomer()
    {


        #####Add sales persion achievement####

        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {

            $date = $_GET['date'];
            $sales_person_id = $_GET['sales_person_id'];
            $sales_person_name = $_GET['sales_person_name'];
            $customer_id = $_GET['customer_id'];
            $customer_name = $_GET['customer_name'];
            $achievement = $_GET['achievement'];
            $query = $this->db->query("insert into ".DB_PREFIX."sales_person_achievement('date') value('".$date."')");
            if($query==false)
            {
                echo ''.mysql_error();
            }

        }
        ##### Add sales persion achievement ####

    }

}

这是我的tpl文件

sales_performance.tpl

<form action="<?php echo $action; ?>" method="POST" class="form-inline" enctype="multipart/form-data">
    <div class="form-group">
        <label for="">Select Date:</label>
        <input type="text" name="date" id="datepicker" class="form-control" placeholder="Select Date">
        <input type="hidden" name="sales_person_id" value="<?php echo $sales_person1['customer_id']; ?>">
        <input type="hidden" name="sales_person_name" value="<?php echo $sales_person1['name']; ?>">
        <input type="hidden" name="customer_id" value="<?php echo $customer['customer_id'];; ?>">
        <input type="hidden" name="customer_name" value="<?php echo $customer['name'];; ?>">
    </div>
    <div class="form-group">
        <label for="">Fill Achievement Amonut:</label>
        <input type="number" name="achievement" class="form-control" placeholder="Achievement Amount">
    </div>
    <div class="form-group">
        <input type="submit" id="saveachievement" name="save" class="btn btn-primary">
    </div>
    </form>
    <script type="text/javascript">
    $('#saveachievement').on('click', function() {
        var date = document.getElementsByName('date')[0].value;
        var sales_person_id = document.getElementsByName('sales_person_id')[0].value;
        var sales_person_name = document.getElementsByName('sales_person_name')[0].value;
        var customer_id = document.getElementsByName('customer_id')[0].value;
        var customer_name = document.getElementsByName('customer_name')[0].value;
        var achievement = document.getElementsByName('achievement')[0].value;
        //alert(achievement);
        location="index.php?route=product/sales_performance&sales_person_id="+sales_person_id+"&customer_id="+customer_id;
    });
</script>

1 个答案:

答案 0 :(得分:1)

实际上我错过了拼写的价值

$query = $this->db->query("insert into ".DB_PREFIX."sales_person_achievement('date') value('".$date."')");

更改为

$query = $this->db->query("insert into ".DB_PREFIX."sales_person_achievement('date') values('".$date."')");

我的意思是value更改为values

现在正在运作。