表单上的空白页提交codeigniter

时间:2016-08-12 03:41:01

标签: php codeigniter

每次我尝试提交表单时,都会转到空白页面。我尝试过启用错误报告,但没有提出任何建议。以下是我的MVC

模型

public function create($email, $password)
{
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean|is_unique[user.email]');
    if ($this->form_validation->run()== false) {
        return false;
    }
        $result = $this->db->insert('user', [
            'email' => $email, 
            'password' => sha1($password . HASH_KEY)
        ]);
            if($this->db->affected_rows()>0)
        {
            redirect(base_url().'admin/view_user');
        } 
}

查看

public function create($email, $password)
{
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean|is_unique[user.email]');
    if ($this->form_validation->run()== false) {
        return false;
    }
        $result = $this->db->insert('user', [
            'email' => $email, 
            'password' => sha1($password . HASH_KEY)
        ]);
            if($this->db->affected_rows()>0)
        {
            redirect(base_url().'admin/view_user');
        } 
}

控制器

public function create_user ()
    {
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        $this->load->model('Users_model');
        $this->Users_model->create($email, $password);
    }

1 个答案:

答案 0 :(得分:0)

查看

<form action="<?php echo base_url();?>/controller/insert_user" method="POST">
<input type="text" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="submit>
</form>

CONTROLLER 已更新

 function insert_user()
{
    $this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');

    $email = $this->input->post('email');
    $password = $this->input->post('password');

    //Set your validations here

    if ($this->form_validation->run()== false) 
    {
        return false;
    }
    else
    {
         $data = array('email'=>$email,
                       'password'=>sha1($password . HASH_KEY)
                      );
         $this->Users_model->insert_user_to_db($data);
         redirect(base_url().'admin/view_user');
     }
}

<强> MODEL

function insert_user_to_db($data)
{
    $this->db->insert('YOUR_TABLE',$data);
}

查看应该是HTML 控制器应包含您想要的所有功能 模型应该只处理数据库

看起来您希望电子邮件在数据库中是唯一的,您也可以通过放置从数据库获取所有电子邮件的代码来实现,如果匹配,则会再次失败。你把它放在//设置你的验证

如果您需要更多帮助,请告诉我

古德纳克!!!