gpt4 book ai didi

php mysql(插入查询)

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

我有简单的付款表单,其中包括voucher_idcustomer_idamount payment_typetransaction_type日期

Transaction_type 是提款和存款。

我的数据库表不应包含“金额”列。它有贷方和借方栏。在这种情况下,如果 INSERT 金额的交易 type ="Withdraws",我希望将 INSERT 金额添加到 debit 列如果 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_typebalance 是有原因的吗?

关于php mysql(插入查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24110554/

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