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

2 回答 2

0
于 2012-06-25T05:22:44.987 回答
0

所以盯着这个看了一会儿,是我的错,但我很困惑没有人拿起它!

问题是这样的:

if($go = 1){

应该

if($go == 1){

这解决了这个问题。

但是由于您的建议,我现在无论如何都要重写它。

编辑:刚刚注意到米莎对此发表了评论!

于 2012-07-04T12:31:26.283 回答