How can i transfer fund to a specific user by getting his/her userID? (Codeigniter)

Viewed 57

Newbie here. My target is to get the ID of the person that I'm going to transfer with. For example: His userID = 4. The userID in my database userID column should be = 4. I have provided screenshot below for better explanation. Thank you in advance

https://prnt.sc/w9piat << Screenshot of my problem and my target

Views:

<button data-id="<?php echo $rows->userID; ?>" class=" fundTable btn btn-success btn-sm text-bold " type="button"  data-toggle="modal" data-target="#fundModal">
  <i class="fas fa-hand-holding-usd mr-1"></i> <?php echo $rows->userID; ?>FUND
</button>

Controller:

public function form_validation()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules("amount","Amount", 'required|numeric');
        
        if($this->form_validation->run())
        {
            
            $ref= $this->session->userdata('userID') + time ();
            
            
            $data = array(
                'userID' => $this->session->userdata('uid'),
                'transactionSource' => 'fund',
                'refNumber' => 'FI' . $ref,
                "amount" =>$this->input->post("amount"),
                "transType" =>"in",
                
                
            );
            $ref= $this->session->userdata('userID') + time ();
            
            $data1 = array(
                'userID' => $this->session->userdata('uid'),
                "transactionSource" => 'fund',
                "refNumber" => 'FO' . $ref,
                "amount" =>$this->input->post("amount"),
                "transType" =>"out",
                
                
            );
            
            
            $this->networks->insert_data($idata, $idata1);
            
          
            
            redirect(base_url() . "network/agents");
        }
        
        else
        {
            $this->index();
        }
        
    }

Model:

function insert_data($data,$data1)
    {
        

        
        $sql1 = "select * from transaction_ledger where userID = ?  order by ledgerID desc limit 0,1";
        $Q1 = $this->db->query($sql1, $data['userID']);
        
        $R1 = $Q1->row_array();
        $ref= $this->session->userdata('userID') + time ();
        
        $idata = array(
            'userID' => $data['userID'],
            'transactionSource' => 'Fund',
            'transType' => 'out',
            'refNumber' => 'FO' . $ref,
            'amount' => $data['amount'],
            'currentBalance' => $R1['currentBalance'] - $data['amount'],
            'previousBalance' => $R1['currentBalance'],
            
        );
        
        $this->db->insert('transaction_ledger', $idata);
        
       
        //update current wallet
        $sqlUpdate = "update users set currentPoints = '".$idata['currentBalance']."', dateUpdated = '".date('Y-m-d h:i:s')."'where userID = ?";
        
        $this->db->query($sqlUpdate, $data['userID']);
        
       
        
        //update you will get the fund
        
        
        
        $idata1 = array(
          //  'userID' => $data['userID'],  (My target is, the ID of the person that i will transfer the fund. How can i get his/her ID? 
            'transactionSource' => 'Fund',
            'transType' => 'in',
            'refNumber' => 'FI' . $ref,
            'amount' => $data['amount'],
            'currentBalance' => $R1['currentBalance'] + $data['amount'],
            'previousBalance' => $R1['currentBalance'],
            
        );
        $this->db->insert('transaction_ledger', $idata1);
        
        $sqlUpdate = "update users set currentPoints = '".$idata1['currentBalance']."', dateUpdated = '".date('Y-m-d h:i:s')."'where userID=0";
        
        $this->db->query($sqlUpdate, $data['userID']);
    }
       

}
1 Answers

In your modal form add a hidden field that holds the ID of the user you want to fund. Every time you click the "Fund" button you get the ID of that button then add it on the modal form hidden field and in that way you can pass that value together with the amount.

<!-- 5 is the id person that going to transfer with -->
<button data-id="7" class="showmodal" class="fundTable btn btn-success btn-sm text-bold">
  <i class="fas fa-hand-holding-usd mr-1"></i> 5 FUND
</button>

<div id="fundModal" class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="#">
          <input type="text" id="usertransferid"> 
          <input type="number" id="amount">
        </form>
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

You can test it here https://jsfiddle.net/renzuii/tvnjf172/

Related