如果条件满足,PHP mysql更新并插入

标签 php mysql

使用以下代码,我尝试使用发布值更新表格。更新后,使用相同的变量,我试图将值插入到具有 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)";
      }
}?>

预先感谢所有支持。

最佳答案

在你的代码中,你永远不会用你的 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);
}

关于如果条件满足,PHP mysql更新并插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31385576/

相关文章:

php - 如何在 Yii 中获取不带参数的当前 url?

php - 用mysql隐藏显示div?

php - MySQL:通过单词搜索缩短查询时间

php - 需要 MySQL 帮助 - 在尽可能少的查询中添加问题/答案?

mysql - 元旦12-2按月选择记录

mysql - 如何强制 Mysql 在 IN 子句中使用主索引...?

PHP/MySQL > 单击链接时更新字段

php - 在 zend 中在哪里保存自定义自动加载器?

MySQL 授予所有命令?

c++ - 旧版 MySQL 连接器 C++ 使用 sql::ConnectOptionsMap 异常