我有简单的支付形式,它是包括voucher_id
,customer_id
,amount
,payment_type
,transaction_type
和date
。
Transaction_type是提款和入金。
我的数据库表不应包含“金额”列。它具有贷方和借方列。在这种情况下,我想INSERT
达debit
列,如果交易type ="Withdraws"
的INSERT
金额信用栏如果Transaction_type ="Deposits"
。
当我INSERT
向表显示数据时:
列数与第1行的值数不匹配
因为,表有借方和贷方列。但是我的表格只有一栏,它的名称就是数量。如何插入此查询以解决我的问题。
<?php
// save data if form is submitted
if(isset($_POST['submitted'])){
// catch data
$voucher_numebr = $_POST['voucher_numebr'];
$member_id = $_POST['member_id'];
$amount = $_POST['amount'];
$acc_type = $_POST['acc_type'];
$payment_type = $_POST['payment_type'];
$discription = $_POST['discription'];
$created = date("Y-m-d H:i:s");
// $balance = $_POST['balance'];
$tranaction_type = $_POST['tranaction_type'];
$balance="NOT DEFINE";
//insert to the tbl_customer_account
if($tranaction_type == "Withdrawls."){
//echo "1";
$sql ='INSERT INTO tbl_customer_account VALUES(NULL,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'","'.$tranaction_type.'","'.$balance.'")';
}
else{
$sql ='INSERT INTO tbl_customer_account VALUES(NULL,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'")';
}
//else{
//}
mysql_query($sql, $conn) or die(mysql_error());
echo 'form submitted';
echo '<br />';
echo mysql_affected_rows(); die();
}
?>
由于您没有为每个列指定值,因此必须指定要更新的列。即使更新所有列,这也是一个好习惯,因此您不必担心将来对表结构的更改(例如,添加或移动列)。
您尚未包括表结构,因此我不得不猜测您的列名:
if($tranaction_type == "Withdrawls."){
//echo "1";
$sql ='INSERT INTO tbl_customer_account (some_field, voucher_number, member_id, debits, account_type, payment_type, description, created, transaction_type, balance) VALUES(NULL,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'","'.$tranaction_type.'","'.$balance.'")';
}
else{
$sql ='INSERT INTO tbl_customer_account (some_field, voucher_number, member_id, credits, account_type, payment_type, description, created) VALUES(NULL,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'")';
}
我想有你离开了原因transaction_type
和balance
存款?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句