数据未发布到phpmyadmin(使用codeigniter构建)

时间:2015-12-18 14:14:33

标签: php codeigniter phpmyadmin

控制器调用请求表单视图...

public function requestform(){

$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('model_orders');

$data['title'] = 'Request Advice';
$this->load->view('header', $data);
$this->load->view('requestform');
$this->load->view('footer');

$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('product_required', 'Product Required', 'required');
$this->form_validation->set_rules('problem_duration[]', 'Problem Duration', 'required');
$this->form_validation->set_rules('terms', 'Terms and Conditions', 'required');

if ($this->form_validation->run() == FALSE) {

    $data['title'] = 'Request Advice';
    $this->load->view('header', $data);
    $this->load->view('requestform', $data);
    $this->load->view('footer');
} else {

    $order_array = array(
        'id'                => NULL,
        'email'             => $this->input->post('email'),
        'product_required'  => $this->input->post('product_required'),
        'problem_duration'  => implode(', ', $_POST['problem_duration'])
        );

        $insert_order = $this->model_orders->insert_order($order_array);
        $this->load->view('homepage', $data);
        }
    }

public function accept_terms($value) {

    if ($value == 'accept') {
        return TRUE;
    } else {
        return FALSE;
}
}

Requestform视图:

<body>
<div id="body">
<?php
echo validation_errors();
echo form_fieldset('Email');

$data = array(
    'name'  => 'email', 
    'id'    => 'email',
    'value' => 'Type email address',
    'maxlength' => '100',
    'size' => '50',
    'style' => 'width:250px',
    );
$js = 'onClick="alert(\'Enter in details!\')"';
echo form_input($data, '', $js);
echo form_fieldset_close();


echo form_fieldset('Choose product required for advice (dropdown)');
$options = array(
    'aloeverajuice' => 'Aloe Vera Juice',
    'aloeveraskin' => 'Aloe Vera Skincare',
    'aloeveragel' => 'Aloe Vera Gel',
    );
echo form_dropdown('product_required', $options, 'aloeverajuice');
echo form_fieldset_close();

echo form_fieldset('How long has the particular problem gone on for? (multi-select)');
$preselected = array('sevendays', 'onemonth', 'sixmonths', 'twelvemonths');
$problem = array(
    'sevendays' => 'Seven Days',
    'onemonth' => 'One Month',
    'sixmonths' => 'Six Months',
    'twelvemonths' => 'Twelve Months',
    );
echo form_dropdown('problem_duration[]', $problem, $preselected);
echo form_fieldset_close();

echo form_fieldset('Terms and Conditions');
echo form_label('Do you agree to our t&c? '. 'terms');
echo form_checkbox('terms', 'accept', TRUE);


echo form_submit('mysubmit', 'Submit');
echo form_close();


?>
</div>
</body>
</html>

此特定形式的模型:

    function __construct() {
        parent::__construct();
    }
    function insert_order($order) {

    $sql = $this->db->insert_string('orders', $order);
    $query = $this->db->query($sql);

    if ($query === TRUE) {
        return TRUE;

        } else {
            $last_query = $this->db->last_query();
            return $last_query;
            }

    }

}

以下是一些有助于理解控制器的内容。我似乎无法在数据库中发布任何内容。

1 个答案:

答案 0 :(得分:0)

在模型中,而不是

 $sql = $this->db->insert_string('orders', $order);
 $query = $this->db->query($sql);

使用

$query = $this->db->insert('orders', $order);