-2

I copied a project from one PC to another PC. When I'm submitting a form, I'm getting an error. This project was working well on my first PC, but I don't know how to solve it, I searched too much, I found topics says the problem is in the PHP version, but I still don't know how to solve it. Also, if it's my problem, this is my error:

Message: The each() function is deprecated. This message will be suppressed on further calls

Filename: core/Security.php

Line Number: 357

Backtrace:

File: C:\xampp\htdocs\Elvan\application\models\Out_m.php Line: 82 Function: post

File: C:\xampp\htdocs\Elvan\application\controllers\Order.php Line: 36 Function: send

File: C:\xampp\htdocs\Elvan\index.php Line: 315 Function: require_once

and this is my model

function send()
    {
        date_default_timezone_set('Africa/Cairo');
        //////////////////////////////////////////////////////////////////
        // to get user id
        $session_data = $this->session->userdata('logged_in');
        $name = $session_data['username'];
        $this->db->select('u_id,u_name,u_username,u_company_id');
        $this->db->from('users');
        $this->db->where('u_username', $name);
        $user_data = $query = $this->db->get();
        if ($user_data->num_rows() > 0) {

            foreach ($query->result_array() as $row_userdata) {

                $mydata[] = $row_userdata;
            }
        }
        $user_id = $mydata[0]['u_id'];
        $user_name = $mydata[0]['u_name'];
        $usercompanyid=$mydata[0]['u_company_id'];
        ///////////////////////////////////////////////////////////////////
        // to get product name based on product id -  this un used i can delete this anytime . 
        $this->db->select('p_name,p_qty');
        $this->db->from('products');
        $this->db->where('p_id', $this->input->post('p_id_select'));
        $query = $this->db->get();
        if ($query->num_rows() > 0) {

            foreach ($query->result_array() as $row) {

                $data[] = $row;
            }
        }
        $post = $this->input->post();

        ////////////////////////////////////////////////////////////////////////
        // get the Customer name to sava it into invoice table 

        $this->db->select('*');
        $this->db->from('customers');
        $this->db->where('c_company_id',$usercompanyid);
        $this->db->where('c_id',$this->input->post('customer_name'));
        $query=$this->db->get();
        if ($query->num_rows() > 0) {

            foreach ($query->result_array() as $row_custdata) {

                $mycust[] = $row_custdata;
            }
        }
        $customer_n = $mycust[0]['c_name'];

        // Select the payment term from database 

        $this->db->select('*');
        $this->db->from('payment_method');
        $this->db->where('p_company_id',$usercompanyid);
        $this->db->where('p_id',$this->input->post('payment_term'));
        $query=$this->db->get();
        if ($query->num_rows() > 0) {

            foreach ($query->result_array() as $row_custdata) {

                $payment[] = $row_custdata;
            }
        }
        $paymnet_name=$payment[0]['p_name'];

        // check if the invoice details if already exist or not . . . . . 

        $this->db->select('*');
        $this->db->from('invoices');
        $this->db->where('i_company_id',$usercompanyid);
        $this->db->where('i_number',$this->input->post('invoice_number'));
        $this->db->where('i_customer_id',$this->input->post('customer_name'));
        $query=$this->db->get();
        if($query->num_rows()==0){

            $invoice_data=array(
            'i_number'=>$this->input->post('invoice_number'),
            'i_customer_id'=>$this->input->post('customer_name'),
            'i_payment'=>$this->input->post('payment_term'),
            'i_payment_name'=>$paymnet_name,
            'i_u_id'=>$user_id,
            'i_u_name'=>$name,
            'i_company_id'=>$usercompanyid,
            'i_date'=>date('Y-m-d H:i:s'),
            'i_branch'=>$this->input->post('branch'),
            'i_customer_name'=>$customer_n

            );
            $this->db->insert('invoices',$invoice_data);
        }


        ////////////////////////////////////////////////////////////////////////////
        // check Qty for all products 
        for ($i = 0; $i < count($post['select_product']); $i++) {
            $this->db->select('*');
            $this->db->from('stock');
            $this->db->where('s_p_id',$post['select_product'][$i]);
            $query=$this->db->get();
            if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row){
                $stockdata[]=$row;
            }
            }
            if ($stockdata[$i]['s_p_qty']<$post['qty'][$i]){
                $this->session->set_flashdata('error',' Please check your stock quantities');
                redirect('Order', 'refresh');
                die();
            }
        }

        //////////////////////////////////////////////////////////////////////////
        // loop area 
        $post = $this->input->post();

        for ($i = 0; $i < count($post['select_product']); $i++) {
            $this->db->select('c_name');
            $this->db->from('customers');
            $this->db->where('c_id',$post['customer_name']);
            $query=$this->db->get();
            if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row){
                $customer[]=$row;
            }
            }
            $session_data = $this->session->userdata('logged_in');
            $name = $session_data['username'];
                $this->db->select('u_money');
                $this->db->from('users');
                $this->db->where('u_username', $name);
                $user_data = $query = $this->db->get();
                if ($user_data->num_rows() > 0) {

            foreach ($query->result_array() as $row_userdata) {

                $mymoney[] = $row_userdata;
            }
            }
            $user_money=$mymoney[$i]['u_money'];

            $this->db->select('p_price,p_name,p_tax');
            $this->db->from('products');
            $this->db->where('p_id',$post['select_product'][$i]);
            $query=$this->db->get();
            if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row){
                $productdata[]=$row;
            }
            }
            $this->db->select('*');
            $this->db->from('stock');
            $this->db->where('s_p_id',$post['select_product'][$i]);
            $query=$this->db->get();
            if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row){
                $stockdata1[]=$row;
            }
            }
            if ($post['qty'][$i] <=0 || $post['price'][$i]<=0 ||$post['total'][$i]!=$post['qty'][$i] * $post['price'][$i] ){
                die();
                }
                else
                {
                if ($stockdata1[$i]['s_p_qty']>=$post['qty'][$i]){
                    $priceandtax=$productdata[$i]['p_price']+$productdata[$i]['p_tax'];
                    $data1 = array(
                    't_customer_id' => $post['customer_name'],
                    't_customer_name'=>$customer[$i]['c_name'],
                    't_order_number' => $post['invoice_number'],
                    't_branch' => $post['branch'],
                    't_p_name'=>$productdata[$i]['p_name'],
                    'payment' => $post['payment_term'],
                    't_p_id' => $post['select_product'][$i],
                    'payment_name'=>$paymnet_name,
                    't_qty' => $post['qty'][$i],
                    't_p_price' => $productdata[$i]['p_price'],
                    't_p_tax'=>$productdata[$i]['p_tax']*$post['qty'][$i],
                    't_p_total_price' =>$productdata[$i]['p_price']*$post['qty'][$i],
                    't_u_id'=>$user_id,
                    't_u_name'=>$user_name,
                    't_date'=>date('Y-m-d H:i:s'),
                    't_company_id'=>$usercompanyid
                    );
                    $this->db->insert('transactions', $data1);
                    $new_qty=$stockdata1[$i]['s_p_qty']-$post['qty'][$i];
                    $stock=array('s_p_qty'=>$new_qty);
                    $this->db->where('s_p_id',$post['select_product'][$i]);
                    $this->db->where('s_company_id',$usercompanyid);
                    $this->db->update('stock',$stock);

                    $total_money=$priceandtax*$post['qty'][$i];
                    $mny_up=array('u_money'=>$total_money+$user_money);
                    $this->db->where('u_id',$user_id);
                    $this->db->update('users',$mny_up);

                    $this->db->set('i_total', 'i_total + ' . $total_money, FALSE);
                    $this->db->set('i_sub_total', 'i_sub_total + ' .$productdata[$i]['p_price']*$post['qty'][$i], FALSE);
                    $this->db->set('i_tax', 'i_tax + ' . $productdata[$i]['p_tax']*$post['qty'][$i], FALSE);
                    $this->db->where('i_company_id',$usercompanyid);
                    $this->db->where('i_number',$post['invoice_number']);
                    $this->db->where('i_customer_id',$this->input->post('customer_name'));
                    $this->db->update('invoices');

                }

            }
        }
    }
Binar Web
  • 867
  • 1
  • 11
  • 26
Syam
  • 169
  • 1
  • 10
  • 2
    It's not CodeIgniter that has deprecated the `each()` function, it's PHP - http://php.net/manual/en/function.each.php - so downgrade the version of PHP, or rewrite the code to avoid using that function – Mark Baker Apr 18 '18 at 21:36

1 Answers1

2

silent operator = the rope to hang yourself.

-       while (list($key, $val) = each($list)) {
+       foreach ($list as $key => $val) {