表单不将输入数据添加到db表

时间:2017-09-14 19:50:04

标签: php html opencart

我正在开发一个Opencart项目,我无法将输入数据输入db表。目前,当我提交它时,它会在数据库中输入一个空记录。 我有一个有几个输入和一个保存按钮的表单。当在phpmyadmin中输入时,模型中的查询工作正常,因此我在视图和控制器之间存在问题。这是一个很大的问题,对我来说过于混乱。任何帮助,将不胜感激     HTML:       " class =" btn btn-primary">

<form method="post" enctype="multipart/form-data" id="form-campaign" class="form-horizontal">

  <div class="form-group">
    <div class="col-sm-5 col-sm-push-1 form-group required>
      <label class="col-sm-2 control-label" for="input-campaign-name"><?php echo $entry_name; ?></label>
      <input type="text" name="name" value="" placeholder="<?php echo $entry_name; ?>" id="input-campaign-name" class="form-control" />
      <?php if (isset($error_name[$language['language_id']])) { ?>
      <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
      <?php } ?>
      </div>
    </div>

    <div class="col-sm-5 col-sm-push-1 form-group required>
      <label class="col-sm-2 control-label" for="input-campaign-goal"><?php echo $entry_goal; ?></label>
      <input type="text" name="goal" value="" placeholder="<?php echo $entry_goal; ?>" id="input-campaign-goal" class="form-control" />
      <?php if (isset($error_name[$language['language_id']])) { ?>
      <div class="text-danger"><?php echo $error_name[$language['language_id']]; ?></div>
      <?php } ?>
    </div>
  </div>                        

</form>

php:controller

public function add() {
        $this->load->language('campaigns/campaign');

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

        $this->load->model('campaigns/campaign');

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


            $this->model_campaigns_campaign->addCampaign($this->request->post);

            $this->session->data['success'] = $this->language->get('text_success');

            $url = '';

            if (isset($this->request->get['filter_campaign_id'])) {
                $url .= '&filter_campaign_id=' . $this->request->get['filter_campaign_id'];
            }

            if (isset($this->request->get['filter_campaign_name'])) {
                $url .= '&filter_campaign_name=' . urlencode(html_entity_decode($this->request->get['filter_campaign_name'], ENT_QUOTES, 'UTF-8'));
            }

            if (isset($this->request->get['filter_campaign_goal'])) {
                $url .= '&filter_campaign_goal=' . $this->request->get['filter_campaign_goal'];
            }

            if (isset($this->request->get['order'])) {
                $url .= '&order=' . $this->request->get['order'];
            }

            if (isset($this->request->get['page'])) {
                $url .= '&page=' . $this->request->get['page'];
            }

            $this->response->redirect($this->url->link('campaigns/campaign', 'token=' . $this->session->data['token'] . $url, true));
        }

        $this->getForm();

    }

php:model

public function addCampaign() {

        $this->db->query("INSERT INTO " . DB_PREFIX . "campaigns SET campaign_name = '" . $this->db->escape($data['campaign_name']) . "', campaign_giving_goal = '" . (float)$data['campaign_giving_goal']
        . "', campaign_giving_count_goal = '" . (float)$data['campaign_giving_count_goal'] . "', campaign_owner = '" . $this->db->escape($data['campaign_owner']). "'");




        $this->cache->delete('campaign');

        return $campaign_id;
    }

0 个答案:

没有答案