PHP代码工作正常但验证消息没有显示

时间:2017-05-14 15:34:09

标签: php mysql

我希望在for循环中运行MySQL更新查询后显示验证消息。我在下面编写了源代码,但验证消息没有显示出来。我不知道是怎么回事。

这是我的PHP代码

<?php
    // Update All rows start
    for ($i=0; $i<$setTotalRows ; $i++) 
    {
        $GetChecked = isset($_POST['txtChecked'.$i]);   
        $GetTransCode = $_POST['txttransCode'.$i];
        $GetTransType = $_POST['txttransSetType'.$i];
        $GetTransMethod = $_POST['txtPaymentMethod'.$i];
        $SetEncodedDate = date("Y-m-d H:i:s");
        if (empty($GetChecked)) { //Start Else
            continue;
        } else if (!empty($GetChecked) && $GetTransType == "ErrorType") {
            continue;
        } else {
            if($GetTransType == "Debit") { //Check For Cashin Cashout Start
                $SetTableName = "tblbank_cashin";
            } else {
                $SetTableName = "tblbank_cashout";
            } //Check For Cashin Cashout End

            //Method Start
            switch ($GetTransMethod) {
                case "1":
                    $SetPayMode = "Cash Deposit";
                    break;
                case "2":
                    $SetPayMode = "Online Transfer";
                    break;
                case "3":
                    $SetPayMode = "Cheque Transfer";
                    break;
                case "4":
                    $SetPayMode = "Cash Withdrawal";
                    break;
                case "5":
                    $SetPayMode = "Cheque Withdrawal";
                    break;
                default:
                    $SetPayMode = "Cash Deposit";
            }
// Method End

            $sql_update = "UPDATE ". $SetTableName. " SET ";
            $sql_update .= "transRecon='1'";
            $sql_update .= ", transReconDate='$SetEncodedDate'";
            $sql_update .= ", transType='$SetPayMode'";
            $sql_update .= " WHERE transCode='$GetTransCode'";
            $result_reconcile = mysqli_query($conn,$sql_update);
            if(!$result_reconcile){
                die("SQL Error: " . mysqli_error($conn));
            //echo $result_reconcile;
            }
        } //End Else

    } //End For i loop

    if(isset($result_reconcile)){
        $sucess = "<div class='alert alert-success'><strong><i class='fa fa-check' aria-hidden='true'></i> Perfect!</strong> payment(s) has been reconciled</div>";
        header('Refresh: 3;url=banks?P=All&E='.$view_bankid);
    } else {
        $error_display = "<div class='alert alert-warning'><strong>ERROR!</strong> An error occured. Please Try Again Here</div>";
    }
//Update All rows End
?>

1 个答案:

答案 0 :(得分:1)

必须在显示任何输出之前发送PHP标头,您也永远不会显示$success,因为您只设置变量,从不回显它。

如果你能够使用Javascript,那么在php本身中回显你的$success,那么我建议在下面使用jQuery,在php $success消息之后回显

<script>$(document).ready(function(){
  setTimeout(function(){
    window.location.replace("some webpage here");
  }, 3000);
});</script>