What's wrong with my code? Rows won't show because of $is_add
. But when I change it to $tot_shrs_amt
the rows shows and the value of is_add is 1
case "Compute":
$is_add = $tot_shrs_amt.$bnfts.$dvdnd.$loan.$grcery.$life_insrnce.$funeral_pln.$flu_vccne.$eye_glss;
$tot_shrs_amt = $_POST['total_shares_amount'];
$bnfts = $_POST['benefits'];
$dvdnd = $_POST['dividend'];
$coop_shrs = $_POST['coop_shares'];
$loan = $_POST['loan'];
$grcery = $_POST['grocery'];
$life_insrnce = $_POST['life_insurance'];
$funeral_pln = $_POST['funeral_plan'];
$flu_vccne = $_POST['flu_vaccine'];
$eye_glss = $_POST['eye_glass'];
$tot_ddctns = $_POST['total_deductions'];
if($tot_shrs_amt){
$tot_shrs_amt = 1;
}
if($bnfts){
$bnfts = 1;
}
if($dvdnd){
$dvdnd = 1;
}
if($coop_shrs){
$coop_shrs = 1;
}
if($loan){
$loan = 0;
}
if($grcery){
$grcery = 0;
}
if($life_insrnce){
$life_insrnce = 0;
}
if($funeral_pln){
$funeral_pln = 0;
}
if($flu_vccne){
$flu_vccne = 0;
}
if($eye_glss){
$eye_glss = 0;
}
if($tot_ddctns){
$tot_ddctns = 0;
}
$coopmemID = $_POST['coopmemID'];
$emp_no = trim($_POST['emp_no']);
$coop_shares = $_POST['total_share'];
$total_deductions = $_POST['total_deductions'];
$net_amount = $_POST['net_amount'];
$date_resigned = $_POST['date_resigned'];
$rep1 = str_replace(",", "", $coop_shares);
$rep2 = str_replace(",", "", $total_deductions);
$rep3 = str_replace(",", "", $net_amount);
$sql = "INSERT INTO tb_finalpay (coopmemID, emp_no, total_share, total_deduct, net_amount, date_released, date_resigned) VALUES ('$coopmemID','$emp_no','$rep1','$rep2','$rep3','".date('Y-m-d')."', '$date_resigned')";
$result = $atecCoop->query($sql);
$insert = $atecCoop->insert_id;
$sql2 = "SELECT
p.fpayID, m.cooploanID, YEAR(p.date_resigned) as date_resigned
FROM
tb_cooploan_master as m
INNER JOIN
tb_finalpay as p
ON
m.coopmemID = p.coopmemID
WHERE
clmstID!='NULL' AND p.coopmemID='$coopmemID'";
$result = $atecCoop->query($sql2);
while ($row = $result->fetch_object()){
$cooploanID = $row->cooploanID;
$fpayID = $row->fpayID;
$date_resigned = $row->date_resigned;
$sql3 = "INSERT INTO tb_finalpay_detail (fpayID, cooploanID, syear, is_add) VALUES ($fpayID, $cooploanID, $date_resigned, $is_add)";
$atecCoop->query($sql3);
}
break;
I think here's the problem.
$is_add = $tot_shrs_amt.$bnfts.$dvdnd.$loan.$grcery.$life_insrnce.$funeral_pln.$flu_vccne.$eye_glss;
You are using the string concatenation operator. $is_add
will be a string after concatenating some variables using dot operator. please see this example:
$a = 0;
$b = 1;
$c = 1;
$d = 0;
$e = $a.$b.$c.$d;
var_dump($e);
prints out string(4) "0110"
. So your $is_add
is very likely not 0 or 1. Try var_dumping $is_add
out right before your insert and inspect its value.
If $is_add
needs to be 0 or 1 then you need to use boolean operators instead. You could try something like this:
$is_add = $tot_shrs_amt || $bnfts || $dvdnd || $loan || $grcery || $life_insrnce || $funeral_pln || $flu_vccne || $eye_glss;
In this way $is_add
will be 1 if one of your other variables evaluates to 1. Else it will be 0.