CodeIgniter查询未插入数据库

时间:2011-01-14 17:46:15

标签: codeigniter

这是我的功能:

function create_member()
    {

        $new_member_insert_data = array(
            'first' => $this->input->post('first_name'),
            'last' => $this->input->post('last_name'),
            'email' => $this->input->post('email_address'),         
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password')                        
        );

        $insert = $this->db->insert('members', $new_member_insert_data);
        return $insert;
    }

我的表名为“members”,我可以连接到我的数据库以提取我手动输入的数据。有关为什么不插入我的数据的任何想法?所有字段名称都是正确的,数据在POST中。我回应它来检查这两件事。这是我的表格:

echo form_open('engineering-resources/login/create');

echo form_input('first_name', set_value('first_name', 'First Name'));
echo form_input('last_name', set_value('last_name', 'Last Name'));
echo form_input('email_address', set_value('email_address', 'Email Address'));
?>
</fieldset>

<fieldset>
<legend>Login Info</legend>
<?php
echo form_input('username', set_value('username', 'Username'));
echo form_input('password', set_value('password', 'Password'));
echo form_input('password2', 'Password Confirm');

echo form_submit('submit', 'Create Acccount');
?>

表单操作有一条路由:$route['engineering-resources/login/create'] = "resources/login/create_member";

这是我的控制器:

function create_member()
    {
        $this->load->library('form_validation');
        echo 'hello';
        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');


        if($this->form_validation->run() == FALSE)
        {
            $data['title'] = 'Please Resubmit Your Information';
            $data['main_content'] = 'resources/signup_form';
            $this->load->view('templates/main.php', $data);
        }

        else
        {           
            $this->load->model('login/membership_model');
            echo $this->db->last_query();

            if($query = $this->membership_model->create_member())
            {
                $data['title'] = 'User Area';
                $data['main_content'] = 'resources/logged_in_area';
                $this->load->view('templates/main', $data);
            }
            else
            {
                $this->load->view('resources/signup_form');         
            }
        }

    }

3 个答案:

答案 0 :(得分:2)

您可以使用以下指令启用性能分析:

$this->output->enable_profiler(TRUE);

然后,您可以查看您的查询是否已执行以及是否正确。

答案 1 :(得分:0)

嗯,尝试在控制器中准备你的阵列:

$this->load->model('login/membership_model');
$new_member_insert_data = array(
    'first' => $this->input->post('first_name'),
    'last' => $this->input->post('last_name'),
    'email' => $this->input->post('email_address'),         
    'username' => $this->input->post('username'),
    'password' => $this->input->post('password')                        
);
if($query = $this->membership_model->create_member($new_member_insert_data))

你的模特:

function create_member($data_arr)
{
    $insert = $this->db->insert('members', $data_arr);
    return $insert;
}

答案 2 :(得分:0)