i have a function in SQL that basically validates a SIN number (similar to credit card validation that i have found on the web). I have to make a PHP page that validates a variable passed to it.
Thanks for looking at this. still learning the ins and outs of PHP.
here is the SQL ----->
FUNCTION fcn_SIN (IN_SIN_NUMBER t4a_register_item.sin_number_text%type)
RETURN NUMBER IS
l_total integer:=0;
l_return NUMBER;
l_number NUMBER;
l_check_digit integer;
BEGIN
/*
since 9 digit number then loop 4 times
then take every second number and multiply it by 2
step A, B, and C
*/
FOR iLoop IN 1..4 LOOP
l_number:= to_number(substr(IN_SIN_Number,iloop2,1)2);
IF l_number>9 THEN
l_total_even:=l_total_even + l_number-9;
ELSE
l_total_even:=l_total_even+ l_number;
END IF;
END LOOP;
/*
add 1-3-5-7
step D
*/
For iloop IN 1..4 LOOP
l_total_odd:=l_total_odd+to_number(substr(IN_SIN_Number,iloop*2-1,1));
END LOOP;
/*
Add result of step C and D
step E
*/
l_number_compaire:=l_total_odd+l_total_even
/*
modulus 10 of l_number_compaire
step F
*/
l_number:=l_number_compaire;
-- Go to next 0 Number
WHILE MOD(l_number,10)<>0 LOOP
l_number:=l_number+1;
END LOOP;
/*
a) Make a number out of the 2nd, 4th, 6th and 8th digit 3001
b) Double it 6002
c) Add the digits of the result (may be up to 5 digits to add) 6 + 0 + 0 + 2 = 8
d) Add the 1st, 3rd, 5th and 7th digits of the SIN 4 + 9 + 1 + 7 = 21
e) Add the results of steps c and d 8 + 21 = 29
f) if the result is zero then the check digit is zero otherwise the check digit is the mod 10 result of e.
(Mod 10: Subtract e from the next higher multiple of 10) 30 - 29 = 1
EXAMPLE
123456789 - fake
a) 2468
b) (2468)*2=4936
c) 4+9+3+6=22
d) 1+3+5+7=16
e) 22+16=38
f) 38 MOD 10 (40-38=2) since it isnt equal to zero then this number "123456789" is not valid)
*/