Skip to content
Advertisement

How to compare $typ = $POST[‘type’] with the leave type selected?

Leave Entry Form I am not able to find a way to compare the selected leave type $typ === 2 with the Sick leave id.

The $typ = $_POST[‘typ’] store the leave type obtained from a database such as Annual leave and Sick Leave. If I select the leave type from a form and it is a sick leave then I would just need to insert leave_date and resume_date in leave table otherwise if the selected leave type is annual then I need to insert the leave_date, resume_date in the leave table as well to update the leave_entitlement table just to reduce leave_entitlement balance

This is a excerpt from my form

This my submit

The problem is when I select Annual Leave or Sick Leave from the form my else part of my if statement always executed. Meaning that the leave_entitlement balance is always reduced even when I select Sick Leave

Advertisement

Answer

You use comparator === which will compare both value and data type. The data type of $typ is String so "2" === 2 will return false. If you want to use === you can cast $typ to integer by using (int) $typ or just change === to ==.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement