gpt4 book ai didi

mysql - 数据未正确插入

转载 作者:行者123 更新时间:2023-11-29 20:56:25 25 4
gpt4 key购买 nike

这里有两个名为 services 和 payment 的表,并且有两个用于向其中插入值的表单。当我在 services 中输入数据时,会得到两行名称 id 和 customer_id,我想将这些值生成到payment表同时添加对应的id..这是我的服务表..

    id  code     customer_id    particulars     serialno    complaint   
22 ORD00022 16 tv 100 ddfds
23 ORD00023 19 GH 565 gfdg
24 ORD00024 15 tv 122 sdfsd
25 ORD00025 16 cvbcv 5 tgtdfgfg
26 ORD00026 16 cvbcv 5 tgtdfgfg

这是我的付款表

id      order_id    customer_id   actual_amount   paid_amount   balance     type
3 0 0 250.00 100.00 150.00 Cash
4 0 0 250.00 50.00 100.00 Cash
5 0 0 150.00 50.00 100.00 Credit
10 0 0 500.00 500.00 400.00 Credit
13 26 16 250.00 100.00 0.00 Cash

这是我的查看页面

<li> <a href="" class="make_payment" data-toggle="modal" data-target=".payment" id="<?php echo $row->id; ?>" customer-id="<?php echo $row->customer_id; ?>" >Make Payment</a> </li>
<div class="modal payment">
<div class="modal-dialog">
<form action="<?php echo base_url(); ?>account_control/make_payment" method="post" id="assign-form">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Make Payment</h4>
</div>
<div class="modal-body">
<div class="box-body">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Total Amount</label>

<div class="col-sm-10">
<input type="text" class="form-control" name="total_amount" id="total_amount" placeholder="Total Amount">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Paid Amount</label>

<div class="col-sm-10">
<input type="text" class="form-control" name="paid_amount" id="paid_amount" placeholder="Paid Amount">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Balance</label>

<div class="col-sm-10">
<input type="text" class="form-control" name="balance" id="balance" placeholder="Balance">
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Balance</label>
<div class="col-sm-10">
<select name="type" class="form-control">
<option value="Cash">Cash</option>
<option value="Credit">Credit</option>
</select>
</div>
<div class="clearfix"></div>
</div>
<input type="hidden" name="order_id" id="order_id">
<input type="hidden" name="customer_id" id="customer_id">
</div>


<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Pay">
</div>
</div><!-- /.modal-content -->
</form>

我的 Controller 看起来像这样..

public function make_payment()
{
$status = $this->Account_model->make_payment();
if($status)
{
$this->session->set_flashdata('message','Payment successful');
}
else
{
$this->session->set_flashdata('message','Payment Failed');
}
redirect('account_control/view_order');
}

我的模型看起来像这样

public function make_payment()
{

$paid = $this->input->post('paid_amount');
$total = $this->input->post('total_amount');
$balance = $this->input->post('balance');
$customer_id = $this->input->post('customer_id');
$order_id = $this->input->post('order_id');

$data = array('order_id' => $order_id,
'customer_id' => $customer_id,
'actual_amount'=>$total,
'paid_amount' => $paid,
'balance' => $balance
);

if($this->db->insert('payment',$data))
{
return TRUE;
}
else
{
return FALSE;
}
}

如果两者都包含在一种表单中,我现在可以正确获取它,它显示这样的错误

Error Number: 1048

Column 'order_id' cannot be null

INSERT INTO `payment` (`order_id`, `customer_id`, `actual_amount`, `paid_amount`, `balance`) VALUES (NULL, 'NULL', '100', '50', '50')

Filename: C:/wamp64/www/account/application/models/Account_model.php

Line Number: 196

这是我的 makep payment 的输出 View ,下面的操作显示模式

  S.No    Order #          Date   Particulars   Serial/IME No  Complaints    Action
1 ORD00027 06/07/2016 led 11 sedsdf make payment

2 ORD00026 06/13/2016 cvbcv 5 tgtdfgfg make payment

我在付款表中插入的最后一行是我假设我应该获得的值

最佳答案

在模型中

$paid = $this->input->post('paid_amount');
$total = $this->input->post('total_amount');
$balance = $this->input->post('balance');
$order_id_data = $this->input->post('order_id');
$customer_id_data = $this->input->post('customer_id ');
if(order_id_data ==""){

$order_id="";

}



if(customer_id_data ==""){

$customer_id ="";

}
$data = array('order_id' => $order_id,
'customer_id' => $customer_id,
'actual_amount'=>$total,
'paid_amount' => $paid,
'balance' => $balance
);

if($this->db->insert('payment',$data))
{
return TRUE;
}
else
{
return FALSE;
}

试试这个

关于mysql - 数据未正确插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37591061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com