这里有人知道我为什么不能在付款表中插入数据吗?我只是想插入它,但我得到了这个错误:
未捕获错误:无法将stdClass类型的对象用作C:\examplep\htdocs\acz thesis \app\models\account.php中的数组
第565行:$total_amount = $row['sales_net_amount'];
控制器
public function InsertPaymentSales() {
if(isset($_SESSION['token']) == $this->input->post('token')) {
$data = array(
'payment_amount' => $this->input->post('payment_amount'),
'payment_date' => $this->input->post('payment_date'),
'payment_remark' => $this->input->post('payment_remark'),
'payment_balance' => $this->input->post('payment_balance'),
'payment_sales_id' => $this->input->post('payment_sales_id')
);
$this->model('account')->sales_payment($data);
}
}
型号
public function sales_payment($data) {
$payment_amount = $data['payment_amount'];
$payment_date = $data['payment_date'];
$payment_remark = $data['payment_remark'];
$payment_balance = $data['payment_balance'];
$payment_sales_id = $data['payment_sales_id'];
$query = $this->db->query("SELECT sales_net_amount, sales_balance FROM tbl_sales_details WHERE sales_id = $payment_sales_id");
$row = $query->fetch_object();
$total_amount = $row['sales_net_amount'];
$balance = $row['sales_balance'];
if($payment_amount >= $payment_balance && $balance > 0) {
$query = $this->db->query("INSERT INTO tbl_sales_payments (payment_amount, payment_date, sales_id, payment_remarks)
VALUES($payment_amount, '$payment_date', $payment_sales_id, '$payment_remark')");
if($query) {
$query = $this->db->query("SELECT SUM(payment_amount) as total_payments FROM tbl_sales_payments WHERE sales_id = $payment_sales_id");
$row = $query->fetch_object();
$total_payments = $row['total_payments'];
$total_balance = $total_amount - $total_payments;
$query = $this->db->query("UPDATE tbl_sales_details SET sales_balance = $total_balance WHERE sales_id = $payment_sales_id");
$message = 'Success';
$query ? notify('success', $message, true) : null;
}
} else {
$message = 'Error';
notify_amaran([false,'#4caf50','#fff',$message]);
}
}
你可以试试这个:
$row = $query->fetch(); $total_amount = $row['sales_net_amount'];
我认为在$query上使用fetch_object((会返回一个对象,而不是要与$row['sales_net_amount']
一起使用的关联数组。
因为@绝对不是Rafal已经评论过你不能访问数组的属性
这些线路是错误的
$total_amount = $row['sales_net_amount'];
$balance = $row['sales_balance'];
[..]
$total_payments = $row['total_payments'];
将其更改为
$total_amount = $row->sales_net_amount;
$balance = $row->sales_balance;
[..]
$total_payments = $row->total_payments;