简体   繁体   English

表单上的空白页提交codeigniter

[英]blank page on form submit codeigniter

Every time I try to submit my form it just goes to a blank page. 每当我尝试提交表单时,它都会转到空白页面。 I have tried enabling error reporting but that does not come up with anything. 我尝试过启用错误报告,但没有提出任何建议。 Below is my MVC 以下是我的MVC

Model 模型

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');
        } 
}

View 视图

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');
        } 
}

Controller 调节器

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);
    }

VIEW 视图

<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 Updated 控制器 更新

 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);
}

View should be the HTML Controller should contain all the functions you want Model should only deal with the database 视图应该是HTML控制器应该包含您想要的所有函数Model应该只处理数据库

and it looks like you want the email to be unique in the database, you can also do so by putting a code that gets all emails from the database, then if one matches, it fails again. 看起来您希望电子邮件在数据库中是唯一的,您也可以通过放置从数据库获取所有电子邮件的代码来实现,如果匹配,则会再次失败。 you put that in the //set your validation here 你把它放在//设置你的验证

Let me know if you need more help 如果您需要更多帮助,请告诉我

GOODLUCK!!! 祝好运!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM