MeekroDb issue as the query only performing insert and not update

56 Views Asked by At

My Name is Puvan. Currently I am facing an issue in performing insertUpdate in meekroDb

This is my query

case "profileInfo":

            $profileUpdateId = $_POST['profileUpdateId'] > 0 ? $_POST['profileUpdateId'] : NULL;
            $updateNationalId= $_POST['updateNationalId'] == "" ? NULL : $_POST['updateNationalId'];
            $updateArea = $_POST['updateArea'] == "" ? NULL : $_POST['updateArea'];
            $updateCity = $_POST['updateCity'] == "" ? NULL : $_POST['updateCity'];
            $updateAddress1 = $_POST['updateAddress1'] == "" ? NULL : $_POST['updateAddress1'];
            $updateAddress2 = $_POST['updateAddress2'] == "" ? NULL : $_POST['updateAddress2'];
            $updateAddress3 = $_POST['updateAddress3'] == "" ? NULL : $_POST['updateAddress3'];
            $updateReligion = $_POST['updateReligion'] == "" ? NULL : $_POST['updateReligion'];
            $updateMalaysiaContact = $_POST['updateMalaysiaContact'] == "" ? NULL : $_POST['updateMalaysiaContact'];
            $updateHomeContact = $_POST['updateHomeContact'] == "" ? NULL : $_POST['updateHomeContact'];
            $updateKinName = $_POST['updateKinName'] == "" ? NULL : $_POST['updateKinName'];
            $updateKinRelationship = $_POST['updateKinRelationship'] == "" ? NULL : $_POST['updateKinRelationship'];
            $updateKinAddress = $_POST['updateKinAddress'] == "" ? NULL : $_POST['updateKinAddress'];
            $updateKinContact = $_POST['updateKinContact'] == "" ? NULL : $_POST['updateKinContact'];
            $updateEducation = $_POST['updateEducation'] == "" ? NULL : $_POST['updateEducation'];
            $updateMarital = $_POST['updateMarital'] == "" ? NULL : $_POST['updateMarital'];

            $sql = "SELECT a.id, a.worker_name, a.gender, a.national_id, a.area, a.city, a.address1, a.address2, a.address3, a.religion, a.malaysia_contact,
                            a.home_country_contact, a.kin_name, a.kin_relationship, a.kin_contact_no, a.kin_address, a.education, a.marital
                    FROM rbs_worker a
                    WHERE id = %s";
            $rs = DB::queryFirstRow($sql, $_SESSION['id']);

            
            DB::insertUpdate('tbl_worker_profile_update_request', [
                'id' =>  $profileUpdateId,
                'workerid' => $rs['id'],
                'worker_name' => $rs['worker_name'],
                'gender' => $rs['gender'],
                'national_id' => $rs['national_id'],
                'area' => $rs['area'],
                'address1' => $rs['address1'],
                'address2' => $rs['address2'],
                'address3' => $rs['address3'],
                'religion' => $rs['religion'],
                'malaysia_contact' => $rs['malaysia_contact'],
                'home_country_contact' => $rs['home_country_contact'],
                'education' => $rs['education'],
                'marital' => $rs['marital'],
                'new_national_id' => $updateNationalId,
                'new_area' => $updateArea,
                'new_city' => $updateCity,
                'new_address1' => $updateAddress1,
                'new_address2' => $updateAddress2,
                'new_address3' => $updateAddress3,
                'new_religion' => $updateReligion,
                'new_malaysia_contact' => $updateMalaysiaContact,
                'new_home_country_contact' => $updateHomeContact,
                'new_education' => $updateEducation,
                'new_marital' => $updateMarital, 
                'year' => DB::sqlEval('NOW()'),
                'status' => 1,
                'entry_user' => $username,
                'entry_date' => DB::sqlEval('NOW()')
            ], [
                'new_national_id' => $updateNationalId,
                'new_area' => $updateArea,
                'new_city' => $updateCity,
                'new_address1' => $updateAddress1,
                'new_address2' => $updateAddress2,
                'new_address3' => $updateAddress3,
                'new_religion' => $updateReligion,
                'new_malaysia_contact' => $updateMalaysiaContact,
                'new_home_country_contact' => $updateHomeContact,
                'new_education' => $updateEducation,
                'new_marital' => $updateMarital,
                'completed_by' => null,
                'completed_date' => null,
                'completed_status' => null,
                'year' => DB::sqlEval('NOW()'),
                'status' => 1,
                'entry_user' => $username,
                'entry_date' => DB::sqlEval('NOW()')

            ]);


            // Insert/update into tbl_worker_family_details
            DB::insertUpdate('tbl_worker_family_details', [

                'id' => NULL,
                'profile_id' => $profileUpdateId,
                'workerid' => $rs['id'],
                'worker_name' => $rs['worker_name'],
                'kin_name' => $rs['kin_name'],
                'kin_relationship' => $rs['kin_relationship'],
                'kin_contact_no' => $rs['kin_contact_no'],
                'kin_address' => $rs['kin_address'],
                'new_kin_name' => $updateKinName,
                'new_kin_relationship' => $updateKinRelationship,
                'new_kin_address' => $updateKinAddress,
                'new_kin_contact_no' => $updateKinContact,
                'status' => 1,
                'entry_user' => $username,
                'entry_date' => DB::sqlEval('NOW()')
            ], [
                'new_kin_name' => $updateKinName,
                'new_kin_relationship' => $updateKinRelationship,
                'new_kin_address' => $updateKinAddress,
                'new_kin_contact_no' => $updateKinContact,
                'status' => 1,
                'entry_user' => $username,
                'entry_date' => DB::sqlEval('NOW()')
            ]);

This is my db query. So now for new_kin_name, new_kin_relationship, new_kin_address and new_kin_contact_no' I want to insert and update the record in different table which is in tbl_worker_family_details under same case profileInfo. It do insert the record successfully but it only performing insert and for update it do not working. It store multiple records in the database table. The id is the primary key in tbl_worker_family_details . Should be right, when I update it should update the same record.

I am stucked as I could not find the solution. It would be helpful and I appreciate if anyone can identify my mistake and provide me the solution. If you need more info let me know. Thank you

0

There are 0 best solutions below