表格不发送数据到数据库?

时间:2013-12-17 11:56:44

标签: php mysql database forms

我创建了一个表单,我正在尝试从表单中收集数据以提交到我在mysql中创建的表中。以下是我尝试使用提交此数据的代码,但它无效,我的表格仍为空?

public function action_claimincentive() {
    $this->template->content = View::factory('crm/uk/claim_incentive_form');
    $this->template->content->thanks = false;
    $this->template->content->val = '';
    $this->template->content->post = '';

    if ($this->request->post('form')) {
        $post = $this->request->post('form');

        $stmt = DB::query(Database::INSERT, 'INSERT INTO `claim_incentive_form_data` (`form_id`,`Claimant Name`, `Claimant Postcode`, `Purchase Order No.`, `Claimant Email Address`, `Storename`, `Storetown`, `Date of Sale`, `Date of Delivery`, `Tempur Acknowledgement No.`, `Tempur Product`)
        VALUES (:claimantname, :claimantpostcode, :orderno, :email, :storename, :storetown, :dateofsale, :dateofdelivery, :acknowledgementno, :tempurproduct)');
        $stmt->param(':claimantname', $post['claimantname']);
        $stmt->param(':claimantpostcode', $post['claimantpostcode']);
        $stmt->param(':orderno', $post['orderno']);
        $stmt->param(':email', $post['email']);
        $stmt->param(':storename', $post['storename']);
        $stmt->param(':storetown', $post['storetown']);
        $stmt->param(':dateofsale', $post['dateofsale']);
        $stmt->param(':dateofdelivery', $post['dateofdelivery']);
        $stmt->param(':acknowledgementno', $post['acknowledgementno']);
        $stmt->param(':tempurproduct', $post['tempurproduct']);
        try {
            $stmt->execute();
            $this->template->content->post = $post;
            $this->template->content->thanks = true;
        } catch (Exception $e) {
            FB::error($e);
        }

    }
}

2 个答案:

答案 0 :(得分:1)

插入了11列,但只有10个值。 我认为你不小心包括form_id

答案 1 :(得分:0)

列不匹配错误,form_id值未提供给插入查询及其参数,

    $stmt = DB::query(Database::INSERT, 'INSERT INTO `claim_incentive_form_data` (`form_id`,`Claimant Name`, `Claimant Postcode`, `Purchase Order No.`, `Claimant Email Address`, `Storename`, `Storetown`, `Date of Sale`, `Date of Delivery`, `Tempur Acknowledgement No.`, `Tempur Product`)
            VALUES (:form_id, :claimantname, :claimantpostcode, :orderno, :email, :storename, :storetown, :dateofsale, :dateofdelivery, :acknowledgementno, :tempurproduct)');  

    $stmt->param(':form_id', $post['form_id']);// added form_id here, assumed you can replace by your value 
    $stmt->param(':claimantname', $post['claimantname']);
    $stmt->param(':claimantpostcode', $post['claimantpostcode']);
    $stmt->param(':orderno', $post['orderno']);
    $stmt->param(':email', $post['email']);
    $stmt->param(':storename', $post['storename']);
    $stmt->param(':storetown', $post['storetown']);
    $stmt->param(':dateofsale', $post['dateofsale']);
    $stmt->param(':dateofdelivery', $post['dateofdelivery']);
    $stmt->param(':acknowledgementno', $post['acknowledgementno']);
    $stmt->param(':tempurproduct', $post['tempurproduct']);