Codeigniter无法从数据库访问列

wmvff8tz  于 2023-02-01  发布在  其他
关注(0)|答案(1)|浏览(115)

我试图添加1列在我的代码,列"itemid"使用,但我得到奇怪的错误,当我做的一切如何它应该,错误消息:"未定义的索引:项目标识符"。
我的模特:

function __construct() {
    $this->proTable   = 'web_store';
    $this->transTable = 'purchases_users';
    $this->GameRewards = 'users_items';
}

/*
 * Fetch products data from the database
 * @param id returns a single record if specified, otherwise all records
 */
public function getRows($id = ''){
    $this->db->select('*');
    $this->db->from($this->proTable);
    $this->db->where('status', '1');
    if($id){
        $this->db->where('id', $id);
        $query = $this->db->get();
        $result = $query->row_array();
    }else{
        $this->db->order_by('Title', 'asc');
        $query = $this->db->get();
        $result = $query->result_array();
    }
    
    // return fetched data
    return !empty($result)?$result:false;
}

/*
 * Insert data in the database
 * @param data array
 */
public function insertTransaction($data){
    $insert = $this->db->insert($this->transTable,$data);
    return $insert?true:false;
}

/*
 * Insert data in the database
 * @param data array
 */
public function insertGameRewards($data){
    $insert = $this->db->insert($this->GameRewards,$data);
    return $insert?true:false;
}

我的PayPal控制器:

function  __construct(){
    parent::__construct();
    $this->load->library('paypal_lib');
    $this->load->model('product');
}
 
function success(){
    // Get user session (is it logged in the webpage)
    $Session = $this->session->userdata("Player_Logged");
    
    if($Session) {
    // Get the transaction data
    $paypalInfo = $this->input->post();
    $data['item_name']= $paypalInfo['item_name'];
    $data['item_number']= $paypalInfo['item_number'];
    $data['item_idr']= $paypalInfo['item_idr'];
    $data['txn_id'] = $paypalInfo["txn_id"];
    $data['payment_amt'] = $paypalInfo["payment_gross"];
    $data['currency_code'] = $paypalInfo["mc_currency"];
    $data['status'] = $paypalInfo["payment_status"];
    
    // Get user ID from 'users' table.
    $IGN = $this->session->userdata['Player_Logged']['id'];

    // Pass the transaction data to view
    $this->load->view('paypal/success', $data);
            // Insert the transaction data in the database
                // This "custom" is old method by documentation, updated by me :P ('user_id' is 'UserID' [I changed column name in database])
            //$datatobase['user_id']    = $paypalInfo["custom"];
            $datatobase['UserID']   = $IGN;
            $datatobase['PackageID']    = $paypalInfo["item_number"];
            // ne barai taka e
            $datatobase['itemid']   = $paypalInfo["item_idr"];
            $datatobase['txn_id']   = $paypalInfo["txn_id"];
            $datatobase['payment_gross']    = $paypalInfo["mc_gross"];
            $datatobase['currency_code']    = $paypalInfo["mc_currency"];
            $datatobase['payer_email']  = $paypalInfo["payer_email"];
            $datatobase['payment_status'] = $paypalInfo["payment_status"];

            // Insert the gamerewards data in the database
            $rewardstobase['UserID']    = $IGN;
            $rewardstobase['ItemID']    = $paypalInfo["item_idr"];
            $rewardstobase['EnhID']     = "1957";
            $rewardstobase['Equipped']  = "0";
            $rewardstobase['Quantity']  = "1";
            $rewardstobase['Bank']      = "0";
            
            // Insert the transaction data in the database
            $this->product->insertTransaction($datatobase);
            // Insert the gamerewards data in the database
            $this->product->insertGameRewards($rewardstobase);
    } else {
            echo '<div class="alert alert-warning alert-dismissible fade show" role="alert"><strong>Error</strong> Error :( ! You need to log in to your account first.
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
            $this->output->set_header('refresh:5; url=http://192.168.1.14/web/Home');
    }
}
 
function cancel(){
    // Load payment failed view
    $this->load->view('paypal/cancel');
 }
 
function ipn(){
    // Paypal posts the transaction data
    $paypalInfo = $this->input->post();
    
    if(!empty($paypalInfo)){
        // Validate and get the ipn response
        $ipnCheck = $this->paypal_lib->validate_ipn($paypalInfo);

        // Check whether the transaction is valid
        if($ipnCheck){
            // Insert the transaction data in the database
            $data['user_id']    = $paypalInfo["custom"];
            $data['product_id'] = $paypalInfo["item_number"];
            $data['txn_id'] = $paypalInfo["txn_id"];
            $data['payment_gross']  = $paypalInfo["mc_gross"];
            $data['currency_code']  = $paypalInfo["mc_currency"];
            $data['payer_email']    = $paypalInfo["payer_email"];
            $data['payment_status'] = $paypalInfo["payment_status"];

            $this->product->insertTransaction($data);
        }
    }
}

我的产品控制器:

function __construct() {
    $this->proTable   = 'web_store';
    $this->transTable = 'purchases_users';
    $this->GameRewards = 'users_items';
}

/*
 * Fetch products data from the database
 * @param id returns a single record if specified, otherwise all records
 */
public function getRows($id = ''){
    $this->db->select('*');
    $this->db->from($this->proTable);
    $this->db->where('status', '1');
    if($id){
        $this->db->where('id', $id);
        $query = $this->db->get();
        $result = $query->row_array();
    }else{
        $this->db->order_by('Title', 'asc');
        $query = $this->db->get();
        $result = $query->result_array();
    }
    
    // return fetched data
    return !empty($result)?$result:false;
}

/*
 * Insert data in the database
 * @param data array
 */
public function insertTransaction($data){
    $insert = $this->db->insert($this->transTable,$data);
    return $insert?true:false;
}

/*
 * Insert data in the database
 * @param data array
 */
public function insertGameRewards($data){
    $insert = $this->db->insert($this->GameRewards,$data);
    return $insert?true:false;
}

我尝试添加新字段'item_idr'并使用与此库获取其他字段相同的方法获取列'itemid',但没有成功。我收到错误消息。甚至我收到的错误消息的更多细节:
严重性:通知消息:未定义的索引:item_idr文件名:帐号:20回溯:文件:C:\拉腊贡\www.web\应用程序\控制器\贝宝. php行:20功能:错误处理程序文件:网址:315功能:需要一次'

ccrfmcuu

ccrfmcuu1#

也许您的视图中没有名为“item_idr”的控件。在Paypal.php的第
data['item_idr']= $paypalInfo['item_idr'];
它从
$paypalInfo = $this->input->post();
顺便说一句,您可以使用配置项表单库(see CI documentation for form helper here)提取$_POST值,这样您就可以从表单验证和条目清理中受益。无论如何......返回......您正在使用$_POST ['item_idr'],这就是您得到的错误。因此,它与您的表和数据库无关,但与您的视图没有任何值这一事实有关
<input type="text" name="item_idr" id="item_idr">
或类似

相关问题