Good day!
I have if and else statement for update and insert data to database…
But only the insert statement was work or satisfied,
here is my code:
<?php
include 'config.php';
$currentEmpID = $_SESSION['empID'];
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
//$EMP_NO = $_POST['EMP_NO'];
//$EMP_NO = mysql_real_escape_string($EMP_NO);
$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];
$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);
//==============================Other Deductions=
$BurialSep = $_POST["BurialSep"];
$TaxAjt = $_POST["TaxAjt"];
$CashAdvance = $_POST["CashAdvance"];
$AdvancesShirt = $_POST["AdvancesShirt"];
$AdvancesMed = $_POST["AdvancesMed"];
$AdvancesOthers = $_POST["AdvancesOthers"];
$sql = "SELECT o.EMP_NO, o.BurialSeparationCont, o.TaxAjt, o.CashAdvance, o.AdvanceShirt, o.AdvanceMed, o.AdvanceOther FROM $PAYROLL.other_deductions o WHERE o.EMP_NO = '$empno'";
$rsOtherDed = $conn2->Execute($sql);
$numrows1 = $rsOtherDed->RecordCount();
// var_dump($numrows1);
if($numrows1 > 0){
$saverec['EMP_NO'] = $empno;
$saverec['BurialSeparationCont'] = $BurialSep;
$saverec['TaxAjt'] = $TaxAjt;
$saverec['CashAdvance'] = $CashAdvance;
$saverec['AdvanceShirt'] = $AdvancesShirt;
$saverec['AdvanceMed'] = $AdvancesMed;
$saverec['AdvanceOther'] = $AdvancesOthers;
$updateSQL = $conn2->GetUpdateSQL($rsOtherDed, $saverec);
$conn2->Execute($updateSQL);
//$conn2->debug = true;
}
else{
$sql = "SELECT o.EMP_NO, o.BurialSeparationCont, o.TaxAjt, o.CashAdvance, o.AdvanceShirt, o.AdvanceMed, o.AdvanceOther FROM $PAYROLL.other_deductions o, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
$rsOtherDed = $conn2->Execute($sql);
$saverec['EMP_NO'] = $empno;
$saverec['BurialSeparationCont'] = $BurialSep;
$saverec['TaxAjt'] = $TaxAjt;
$saverec['CashAdvance'] = $CashAdvance;
$saverec['AdvanceShirt'] = $AdvancesShirt;
$saverec['AdvanceMed'] = $AdvancesMed;
$saverec['AdvanceOther'] = $AdvancesOthers;
$insert = $conn2->GetInsertSQL($rsOtherDed, $saverec);
$conn2->Execute($insert);
}
I tried to var_dump the $numrows1 and it has value 1 because I have data already in my database with the o.EMP_NO, but when I tried to edit the data, it did not change in database…
Thank you so much…