I am a new, "trying to be" PHP Html and MySqli programmer coming from Ms Access and VB background. Can somebody please assist, as I am stuck and sweating with these calculations.An y suggestions on how to populate the relevant input text boxes in realtime when adding an IDNo to the screen in input textbox called IDNO? Currently it only populate the mysqli database on pressing the submit button.
Example Identity number = 63021854485519
The Birthdate from this = dd/mm/yyyy = 18/02/1963
In PHP this works, but it does not populate Birthdate input text box in realtime as IDNo is added.
The 7th digit indicates male or female ie 0-4 = female and 5-9 = male , So
this person's Id No indicates its a Male as 7th digit is 5 (between 5-9)
In PHP this works but does not populate gender input textbox in realtime as IDNo is added
Lastly i also need to calculate the AGE of this person from the birthdate as of 31 December of current year (NOT TODAY as this code shows)
In PHP as of today i use
(In VB to calculate birthdate from ID No I use ---> DOB=Mid([idno],5,2) & "/" & Mid([idno],3,2) & "/" & Mid([idno],1,2) Require as dd/mm/yyyy.
(PHP
In VB to calculate Gender I use --> Gender=IIf(Mid([idno],7,1) Between 0 And 4,"Female","Mal e").)
To summarize how can i populate the birthdate, gender and age on screen to the relevant input textboxes, after entering the IDNO onscreen. Pls advise as this causing nightmares in my life.
Example Identity number = 63021854485519
The Birthdate from this = dd/mm/yyyy = 18/02/1963
In PHP this works, but it does not populate Birthdate input text box in realtime as IDNo is added.
Code:
function getBirthdateFromIdentity($identity) {
// substring identity to get bday
$date = substr($identity, 0, 6);
// use built-in DateTime object to work with dates
$date = \DateTime::createFromFormat('ymd', $date);
$now = new \DateTime();
// compare birth date with current date:
// if it's bigger bd was in previous century
if ($date > $now) {
$date->modify('-100 years');
}
return $date;
this person's Id No indicates its a Male as 7th digit is 5 (between 5-9)
In PHP this works but does not populate gender input textbox in realtime as IDNo is added
Code:
function getGenderFromIdentity($identity) {
// substring gender data and convert it to int
$gender = (int) substr($identity, 6, 1);
return ($gender >= 0 && $gender <= 4) ? 'Female' : 'Male';
}
*/
In PHP as of today i use
Code:
function getAgeFromBirthday(\DateTime $birthdate) {
$date = new DateTime();
$interval = $date->diff($birthdate);
return $interval->y;
}
(In VB to calculate birthdate from ID No I use ---> DOB=Mid([idno],5,2) & "/" & Mid([idno],3,2) & "/" & Mid([idno],1,2) Require as dd/mm/yyyy.
(PHP
In VB to calculate Gender I use --> Gender=IIf(Mid([idno],7,1) Between 0 And 4,"Female","Mal e").)
To summarize how can i populate the birthdate, gender and age on screen to the relevant input textboxes, after entering the IDNO onscreen. Pls advise as this causing nightmares in my life.
Comment