为什么form_open没有发布任何内容?

时间:2016-07-25 17:13:57

标签: php codeigniter

我是CodeIgniter和PHP的新手,目前正在尝试制作更改密码脚本。 我的更改密码功能在一个名为scrips的控制器中。不太明白为什么它根本没有发布任何东西。

这是我的控制者:

public function change_password()
{   
    $this->page_handler->member_page();
    $this->load->database();
    $this->form_validation->set_rules('old_pass','Old Password','required');
    $this->form_validation->set_rules('new_pw','New Password','required');
    $this->form_validation->set_rules('conf_pw','Confirm Password','required|matches[new_pw]');

    if($this->form_validation->run() !=true) {
        $sql=$this->db->select("*")->from("members")->where("username", $this->session->userdata("username"))->get();

        foreach ($sql->result() as $my_info) {
            $db_password=$my_info->password;
            $db_id -$my_info->id;
        }

        if(md5($this->input->post("old_pass"))== $db_password) {    
            $fixed_pw = md5(mysql_real_escape_string($this->input->post("new_pw")));
            $update=$this->db->query("UPDATE 'members' SET 'password' = '$fixed_pw' WHERE 'id'='$db_id'") or die(mysql_error());

            $this->session->set_flashdata("notification","Password has been updated!");
            redirect('home_view');
        } else {
            echo "A problem has occurred,please try again.";
            $this->load_view("home_view");    
        }    
    }        
}

这是我的观点:

<?php echo form_open('scripts/change_password') ?> 

    <input placeholder="Old Password" 
           id="old_pass" 
           value="<?php echo set_value(md5('old_pass')); ?> "
           name="old_pass" 
           class="w3-input w3-border"
           type="password" >

    <input placeholder="New Password"
           id="new_pw" 
           value="<?php echo set_value('new_pw'); ?>" 
           name="new_pw" 
           class="w3-input w3-border" 
           type="password">

    <input placeholder="Confirm Password" 
           id="conf_pw" 
           value="<?php echo set_value('conf_pw'); ?>" 
           name="conf_pw"
           class="w3-input w3-border" 
           type="password">

    <input class="w3-margin-top w3-btn w3-hover-white" 
           type="submit" 
           value="Change Password "
           style="width:100%">Change my password</button>

<?php form_close(); ?>

1 个答案:

答案 0 :(得分:0)

看起来问题出在你的change_password()方法中,你正在检查验证器是否在验证:

if($this->form_validation->run() !=true) {
    ...
}

将其更改为:

if($this->form_validation->run() == true) {
   ...
}

它应该有用。