如何解决 Codeigniter 中的“用户名不存在”错误 [已关闭]

问题描述 投票:0回答:2

在我的 codeigniter 脚本中不应该出现错误时出现了错误。 我假设这对我的代码流程来说很简单,但我无法弄清楚。

这是页面:http://77.96.119.180/beer/user/activate/

您可以看到底部出现的错误,这是不应该出现的

“该用户名不存在。”

这是我的 CodeIgniter 类代码:

public function activate($code = '', $username = '')
    {
        $go = 0;
        $form = '';
        // This function lets a user activate their account with the code or link they recieved in an email
        if($code == '' || $username == '' || isset($_POST[''])){
            
            $this->load->library('form_validation');
            $this->load->helper('form');
            
            $this->form_validation->set_rules('code', 'Activation Code', 'trim|required|xss_clean|integer');
            $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
            
            if ($this->form_validation->run() == FALSE){
                // No code, so display a box for them to enter it manually
                $form .= validation_errors();
                $form .= form_open_multipart('user/activate', array('class' => 'formee'));
                
                $form .= form_label('Enter your activation code below and click \'Activate\' to start using your account. If you need a hand please contact live chat.', 'activation_code');
                $form .= form_input(array('name' => 'code'));
                
                $form .= form_label('And enter your username', 'username');
                $form .= form_input(array('name' => 'username'));
                
                $data = array(
                    'name'        => 'submit',
                    'value'       => 'Activate',
                    'class'       => 'right',
                    'style'       => 'margin-top:10px;',
                );
    
                $form .= form_submit($data);
                $form .= form_close();
            }else{
                $go = 1;
                // Put POST variables into variables
                $code = $this->input->post('code');
                $username = $this->input->post('username');
            }
        }else{
            // Code recieved through the GET or POST variable XSS clean it and activate the account
            $go = 1;
            
            // Put GET variables into variables
            $code = $this->uri->segment(3);
            $username = $this->uri->segment(4);
        }
        
        if($go = 1){
            // Activate!
            
            // Check if user exists
            $query = $this->db->get_where('users', array('username' => $username, 'confirmation' => $code), 1);
            if ($query->num_rows() > 0){
                // Username exsists, activate the account
                $data = array(
                   'is_validated' => 1
                );
    
                $this->db->where('username', $username);
                $this->db->update('users', $data);
                
                $form .= '<div class="formee-msg-success">Acount activated, <a href="#">click here</a> to login.</div>'; 

            }else{
                // Username doesn't exsist or code doesn't match, find out which
                $form .= '<div class="formee-msg-error">That username doesn\'t exsist.</div>'; 
            }
        }
        
        
        $data = array(
            'title' => $this->lang->line('activate_title'),
            'links' => $this->gen_login->generate_links(),
            'content' => $form
        );
        $this->parser->parse('beer_template', $data);
    }
php codeigniter flow
2个回答
0
投票

对于 if 语句:

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

删除 else 语句中的 $go = 1。

else
{
   // Put POST variables into variables
   $code = $this->input->post('code');
   username = $this->input->post('username');
 }

当 form_validation->run()=TRUE 且激活码或用户名留空时,此代码块将始终执行。如果没有激活码或用户名,您不会想尝试激活。

此外,下面的代码行没有执行任何操作。您正在引用键 [''],它将始终返回相同的结果。

isset($_POST[''])

从我读过的文档中,您需要输入 $_POST 的密钥。前任。 $_POST['代码'].你可以尝试 isset($_POST),但我也不能 100% 确定这会起作用。您可以在这里阅读更多相关信息:http://us.php.net/isset

编辑: 正如 Mischa 在评论中指出的那样,您在 if 语句中分配 $go=1 。


0
投票

所以看了一会儿之后,这是我的错,但我很困惑没有人捡到它!

问题是这样的:

if($go = 1){

应该是

if($go == 1){

这解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.