Notice: Undefined variable: POST_ in D:\xampp\htdocs\book\creditcard-process.php on line 109
Notice: Undefined variable: POST_ in D:\xampp\htdocs\book\creditcard-process.php on line 109
Notice: Undefined variable: verified in D:\xampp\htdocs\book\creditcard-process.php on line 73
Notice: Undefined variable: denum in D:\xampp\htdocs\book\creditcard-process.php on line 75
POST_ means that you have not implemented the changes suggested. $_POST['...'] is the correct syntax.
$verified will not be set unless one of the conditionals is matched. IMO, you should set $verified right at the start of the function:
$verified = false;
This means the default position is FAIL, it will only read true if the requirements of one of your conditionals is met.
$denum will not exist if it isn't one of:
"American", "Dinners", "Discover", "Master" or "Visa"
You should have a fallback 'else' in the conditional block. Either that or halt the execution is the card is not of an acceptable type.
Personally, I'd hold all allowed cards with patterns in an array:
$check = array('American' => array("American Express", "/^([34|37]{2})([0-9]{13})$/"), 'Dinners' => array("Diner's Club", "/^([30|36|38]{2})([0-9]{12})$/"),...);
...
$verified = false;
if(isset($check[$type])){
$cardlabel = $check[$type][0];
if(preg_match($check[$type][1],$cc_num)) {
$verified = true;
}else{
//this number does not match the card type
}
}else{
//this type of card is not accepted
}
If you trap the errors and stop code execution, e.g. with exit or a header(), you may find that the $verified var is no longer required.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080