-2

私のコードイグナイタースクリプトにあってはならないエラーが表示されています。コードの流れで簡単にできると思いますが、理解できません。

ここにページがあります:

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

それで、これをしばらく見つめた後、それは私のせいでした、しかし私は誰もそれを拾わなかったので混乱しています!

問題はこれでした:

if($go = 1){

する必要があります

if($go == 1){

これで問題は解決します。

しかし、私はあなたの提案のためにとにかくそれを書き直しています。

編集:Mischaがこれについてコメントしていることに気づきました!

于 2012-07-04T12:31:26.283 に答える
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 を割り当てています。

于 2012-06-25T05:22:44.987 に答える