I want to show a validation message after running a MySQL update query in a for
loop. I wrote the source code below but the validation message is not showing up. I don't know what the matter is.
Here is my PHP code
<?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
?>
PHP headers must be sent before any output is displayed, you also are never displaying $success
, as you only set the variable, never echoing it.
If you are able to use Javascript, then echo out your $success
in the php itself, then I would suggest using jQuery for the following, echo'd out after the php $success
message.
<script>$(document).ready(function(){
setTimeout(function(){
window.location.replace("some webpage here");
}, 3000);
});</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.