框架codeigniter $ _POST为null

时间:2015-04-08 17:35:40

标签: php mysql database codeigniter post

我遇到一个小脚本问题我的$ _POST返回null但是我不明白为什么,请帮助我PLZ

我的错误消息:

Error Number: 1048
Column 'credit_id' cannot be null

INSERT INTO `trader_order` (`trader_id`, `credit_id`, `credit`, `amount`, `payment_status`, `added_date`) VALUES ('40', NULL, NULL, NULL, 'No', '2015-04-08 22:59:10')

Filename: /homepages/0/d433601931/htdocs/Wisementrade/new_version/models/trader_model.php

Line Number: 190

PHP控制器:

public function trader_buy_commission(){
    $trader_id=$this->session->userdata('customer_id');
    $cred_id = $_POST["cred_id"];

    $price = $this->trader->getPrice($cred_id);
    $value = $this->trader->verify_credit_amount($_SESSION['credit_session'], $price->price);
    $payment_status="No";
    $_SESSION['credit_trader_amount'] = $price->price;
    $amount=$price->price;
    $credit=$price->credit;
    $orderid = $this->trader->insert_credit_order_detail($trader_id, $cred_id,$credit,$amount,$payment_status);
}

PHP模型:

public function insert_credit_order_detail($trader_id, $cred_id,$credit,$amount,$payment_status){

    $date = date('Y-m-d H:i:s');
    $data = array(
        'trader_id' => $trader_id,
        'credit_id' => $cred_id,
        'credit' =>$credit,
        'amount' => $amount,
        'payment_status' => $payment_status,
        'added_date' => $date
    );
    $this->db->insert('trader_order', $data);
    return $this->db->insert_id();

}

HTML:

<td text align="center">
    <?php
    $credit = $this->trader->getcredit();
    ?>
    <select name="cred_id" id="cred_id" style="height:22px; width:170px;">
        <?php foreach ($credit as $manage) { ?>
        <option value="<?php echo $manage->credit_id; ?>"><?php echo $manage->title; ?></option>
        <?php } ?>
    </select>
</td>
<td align="right"  bgcolor="#FFFFFF" style="padding:10px ;"> <button type="submit" class="search">Pay with Paypal</button>
<td align="right"  bgcolor="#FFFFFF" style="padding:10px ;"> 
    <a class="sdetail_btn validate" href="<?php echo base_url();?>index.php/trader/trader_buy_commission">Pay with Commission</a>
</td>

1 个答案:

答案 0 :(得分:0)

对不起,我对Codeigniter很新,我仍然是学生,所以如果这个答案不是很好,就不要理会。

您的问题是否可以将$ _POST [&#39; cred_id&#39;]设置为$ cred_id

$cred_id = $_POST["cred_id"];

然后再使用$ credit_id?

$this->trader->insert_credit_order_detail($trader_id, $credit_id,$credit,$amount,$payment_status);