简体   繁体   中英

codeigniter error loop with page redirect

Hello I have created an update query using a concept that if the id is valid then it should update the data otherwise it will not do so but when any of the conditions meet it redirects and says page is redirecting to the loop why is this happening so ?

Controller

public function confirm() {
    if($this->session->userdata('is_logged_in') == true) {
        $invc = "#".$this->input->get('id');

        if($invc == true) {
            $this->data_update->update_trans($invc);
        } else {
            redirect('home/confirm');
        }
    } else {
        redirect('user/login');
    }
}

Here is my model file

public function update_trans($invc_id) {
        $get_trans  = $this->db->get_where('transaction', array("invc_id" =>  $invc_id));
        $user_id    = $get_trans->row()->userid;
        $amount     = $get_trans->row()->ammount;

        if(!empty($user_id)) {
            $check     = $this->db->get_where('account', array("user_id" =>  $user_id));
            if($check->row()->balance == true) {
                $new_amount = ($amount + $check->row()->balance);
                $dataupdate = array(
                    'user_id' => $user_id,
                    'balance' => $new_amount
                );

                $this->db->where('id', $user_id);
                $this->db->update('account', $dataupdate);

                $this->db->where('invc_id', $invc_id);
                $this->db->update('transaction', array('status' => 'Confirmed'));
                redirect('home/confirm?id='.$invc_id);
            } else {

                $data1 = array(
                    'user_id' => $user_id,
                    'balance' => $amount
                );

                $this->db->insert('account', $data1);
                $this->db->where('invc_id', $invc_id);
                $this->db->update('transaction', array('status' => 'Confirmed'));

                redirect('home/confirm?id='.$invc_id);
            }
        } else {
            redirect('home/confirm');
        }
    }

And this is my view file

<?php
require('sidebar.php');
    ?>
        <!-- Body Content -->
        <div id="body">
        <?php 
            if($this->input->get('id') == true) {
        ?>
            <div class="msg">
                <h4>Your Payment Has been confirmed successfully</h4>
            </div>
        <?php } else { ?>
            <div class="msg">
                <h4>Payment Not confirmed</h4>
            </div>
        <?php } ?>
        </div>

        <div id="break">&nbsp;</div>

    </div>

I dont know why but it is giving me the same error This webpage has a redirect loop can anyone help me out with this please

In your function its going every time in else part (redirect('home/confirm');) so its showing error. Your function should be like this..

public function confirm() {
    if($this->session->userdata('is_logged_in') == true) {
        $invc = "#".$this->input->get('id');
        if($this->input->get('id')) {
            $this->data_update->update_trans($invc);
        } else {
            redirect('home/confirm');
        }
    } else {
        redirect('user/login');
    }
}

Hope this will solve your issue.

Try your confirm() function as like that:

public function confirm() 
{
    if($this->session->userdata('is_logged_in') == true) {

        $id = intval($this->input->get('id'));
        $invc = "#".$id;

        if($id > 0) {
            $this->data_update->update_trans($invc);
        } else {
            redirect('home/confirm');
        }
    } else {
        redirect('user/login');
    }
}

You are expecting this "#".$this->input->get('id') will return you true or false.

And more if still facing same issue, than check what are you getting in $_GET like:

if($this->session->userdata('is_logged_in') == true) {
    print_r($_GET); // will return you an array
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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