0

i am trying to do credit card validation. the card details are entered n creditcard.php and process in creditcard-process.php

and this is the error for creditcard-process.php.. can i check whats wrong with creditcard-process.php ?

Notice: Use of undefined constant ccnum - assumed 'ccnum' 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: Use of undefined constant cardtype - assumed 'cardtype' 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
Credit card invalid. Please make sure that you entered a valid credit card

<?php 

session_start();

if (!(isset($_SESSION['email']) && $_SESSION['email'] != '')) {
header ("Location: login.php");
}
?>
<?php
include ('includes\header.php');

//function validateCC($cc_num, $type) {
function validateCC($cc_num, $type) {

	if($type == "American") {
	$denum = "American Express";
	} elseif($type == "Dinners") {
	$denum = "Diner's Club";
	} elseif($type == "Discover") {
	$denum = "Discover";
	} elseif($type == "Master") {
	$denum = "Master Card";
	} elseif($type == "Visa") {
	$denum = "Visa";
	}

	if($type == "American") {
	$pattern = "/^([34|37]{2})([0-9]{13})$/";//American Express
	if (preg_match($pattern,$cc_num)) {
	$verified = true;
	} else {
	$verified = false;
	}
	
	
	} elseif($type == "Dinners") {
	$pattern = "/^([30|36|38]{2})([0-9]{12})$/";//Diner's Club
	if (preg_match($pattern,$cc_num)) {
	$verified = true;
	} else {
	$verified = false;
	}
	
	
	} elseif($type == "Discover") {
	$pattern = "/^([6011]{4})([0-9]{12})$/";//Discover Card
	if (preg_match($pattern,$cc_num)) {
	$verified = true;
	} else {
	$verified = false;
	}
	
	
	} elseif($type == "Master") {
	$pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/";//Mastercard
	if (preg_match($pattern,$cc_num)) {
	$verified = true;
	} else {
	$verified = false;
	}
	
	
	} elseif($type == "Visa") {
	$pattern = "/^([4]{1})([0-9]{12,15})$/";//Visa
	if (preg_match($pattern,$cc_num)) {
	$verified = true;
	} else {
	$verified = false;
	}
	
	}
	
	if($verified == false) {
	//Do something here in case the validation fails
	echo "Credit card invalid. Please make sure that you entered a valid <em>" . $denum . "</em> credit card ";
	
	} else { //if it will pass...do something
	echo "Your <em>" . $denum . "</em> credit card is valid";
	}


}
?>

 <div id="central_content"> 

 

      
      <!-- BEGIN central slogan and rss feed -->
 <!--     <div class="rss">Stay tuned with our<a href="#">Feed RSS</a>
        <div id="rss_logo"></div>
      </div> -->
      <div class="question1 ha">Credit Card Payment</div>
      <!--     <div class="question2 ha">New</div>
      <div class="question1 ha">Here?</div> -->
      <div style="clear:both;"></div>
      <div class="slogan">Please enter your credit card detailst</div>
      <br />
      <br />
      <!-- END central slogan and rss feed --> 
      
      <!-- BEGIN central products -->

         <div class="central_products"> 
         
                <span class="slogan" style="padding-top: 12px">
       <?
	echo  validateCC($POST_[ccnum],$POST_[cardtype]);
	//echo validateCC("1738292928284637", "Dinners");	
	   ?>
        </span>
        
              </div>
  

<?php
include ('includes\footer.html');
?>
4
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by issaru07
0

An editor (like Eclipse or Netbeans) could make your life easier. The message is telling you what is wrong.. line 109 …

echo  validateCC($POST_[ccnum],$POST_[cardtype]);

probably you mean

echo  validateCC($_POST["ccnum"],$_POST["cardtype"]);
0

An editor (like Eclipse or Netbeans) could make your life easier. The message is telling you what is wrong.. line 109 …

echo  validateCC($POST_[ccnum],$POST_[cardtype]);

probably you mean

echo  validateCC($_POST["ccnum"],$_POST["cardtype"]);

thanks.. :)
but still there are errors..

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

0

Try declaring denum and verified at the top like this

$denum = ""; 
$verified =false;

and i would suggest if you declare $_POST["ccnum"] and $_POST["cardtype"] in a variable like this

$ccnum = $POST['ccnum'];
$cardtype =$_POST['cardtype'];

Hope it helps :) (I really hate CGI :))

0

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.

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.