使用以下代码,我尝试使用post值更新表。更新后,使用相同的变量,我试图将值插入到具有if条件的另一个表。第一次更新工作正常,但插入没有发生。
<?php
if (isset($_POST['submit'])) {
$wlnid=$_POST['wlt_ln_id'];
$refwal = $_POST['wlt_name'];
$refamt = $_POST['wlt_ln_refund_amt'];
$refdtls = $_POST['wlt_ln_txn_details'];
$refdate = $_POST['wlt_ln_refund_date'];
$lntype = $_POST['wlt_ln_type'];
$query=mysqli_query($GLOBALS["___mysqli_ston"], "update wallet_loans set wlt_ln_refund_acct = '$refwal',wlt_ln_refund_amt=wlt_ln_refund_amt+'$refamt',wlt_ln_refund_txn_details='$refdtls',wlt_ln_refund_date='$refdate' where wlt_ln_id = '$wlnid'and wlt_holder_id = '{$_SESSION['SESS_MEMBER_ID']}'");
if($lntype == 'Given'){
$sql = "INSERT INTO wallet_txns(wlt_name, wlt_txn_date, wlt_txn_type, wlt_drcr_cod, wlt_txn_amount, wlt_txn_dtls, wlt_txn_cat, wlt_txn_cat_sub, wlt_amt_payee, wlt_holder_id, wlt_txn_flg_loan, wlt_txn_ln_id, wlt_txn_flg_recr, wlt_txn_recr_id) VALUES ( '$refwal', '$refdate', 'Income','C', '$refamt', '$refdtls', 'Loan refund','Null','Null', '{$_SESSION['SESS_MEMBER_ID']}', 'Y','$wlnid', 'N',0)";
}
else if($lntype == 'Received'){
$sql = "INSERT INTO wallet_txns(wlt_name, wlt_txn_date, wlt_txn_type, wlt_drcr_cod, wlt_txn_amount, wlt_txn_dtls, wlt_txn_cat, wlt_txn_cat_sub, wlt_amt_payee, wlt_holder_id, wlt_txn_flg_loan, wlt_txn_ln_id, wlt_txn_flg_recr, wlt_txn_recr_id) VALUES ( '$refwal', '$refdate', 'Expense','D', '$refamt', '$refdtls', 'Loan refund','Null','Null', '{$_SESSION['SESS_MEMBER_ID']}', 'Y','$wlnid', 'N',0)";
}
}?>
感谢所有支持。
答案 0 :(得分:1)
在您的代码中,您永远不会使用SQL查询调用mysqli_query
。
if ($lntype == 'Given') {
$sql = "INSERT INTO wallet_txns(wlt_name, wlt_txn_date, wlt_txn_type, wlt_drcr_cod, wlt_txn_amount, wlt_txn_dtls, wlt_txn_cat, wlt_txn_cat_sub, wlt_amt_payee, wlt_holder_id, wlt_txn_flg_loan, wlt_txn_ln_id, wlt_txn_flg_recr, wlt_txn_recr_id) VALUES ( '$refwal', '$refdate', 'Income','C', '$refamt', '$refdtls', 'Loan refund','Null','Null', '{$_SESSION['SESS_MEMBER_ID']}', 'Y','$wlnid', 'N',0)";
mysqli_query($GLOBALS["___mysqli_ston"], $sql);
}
else if($lntype == 'Received'){
$sql = "INSERT INTO wallet_txns(wlt_name, wlt_txn_date, wlt_txn_type, wlt_drcr_cod, wlt_txn_amount, wlt_txn_dtls, wlt_txn_cat, wlt_txn_cat_sub, wlt_amt_payee, wlt_holder_id, wlt_txn_flg_loan, wlt_txn_ln_id, wlt_txn_flg_recr, wlt_txn_recr_id) VALUES ( '$refwal', '$refdate', 'Expense','D', '$refamt', '$refdtls', 'Loan refund','Null','Null', '{$_SESSION['SESS_MEMBER_ID']}', 'Y','$wlnid', 'N',0)";
mysqli_query($GLOBALS["___mysqli_ston"], $sql);
}