jaxdevil Posted December 18, 2007 Share Posted December 18, 2007 Here is the code I am trying, it is all working except displaying the correct cc type. Any idea? <?php $number = "$cc_num"; $last_four = substr($number, -4); $first_one = substr($number, 1); if($first_one=3){$cc_type = 'American Express';} elseif($first_one==4){$cc_type = 'Visa';} elseif($first_one==5){$cc_type = 'MasterCard';} elseif($first_one==6){$cc_type = 'Discover';} else {$cc_type = 'Unknown';} ?> <center> <table width="800" height="50" cellspacing="0" cellpadding="0" border="1" bordercolor="black"> <tr valign="top"> <td width="200" height="10" align="left" valign="top"> <font face="Tahoma" size="2">CARD TYPE</font> </td> <td width="200" height="10" align="left" valign="top"> <font face="Tahoma" size="2">LAST 4</font> </td> <td width="200" height="10" align="left" valign="top"> <font face="Tahoma" size="2">AUTH CODE</font> </td> <td width="200" height="10" align="left" valign="top"> <font face="Tahoma" size="2">AMOUNT</font> </td> </tr> <tr valign="top"> <td width="200" height="40" align="left" valign="top"> <font face="Tahoma" size="2"><?=$cc_type?></font> </td> <td width="200" height="40" align="left" valign="top"> <font face="Tahoma" size="2"><?=$last_four?></font> </td> <td width="200" height="40" align="left" valign="top"> <font face="Tahoma" size="2"><?=$authxyz?></font> </td> <td width="200" height="40" align="left" valign="top"> <font face="Tahoma" size="2"><?=$amount?></font> </td> </tr> </table> </center> Quote Link to comment Share on other sites More sharing options...
xinteractx Posted December 18, 2007 Share Posted December 18, 2007 try something like this... <?php //test number $cc_num = "123312312"; $number = "$cc_num"; $last_four = substr($number, -4); $first_one = substr($number, 1); if($first_one=3){$cc_type = "American Express";} elseif($first_one==4){$cc_type = "Visa";} elseif($first_one==5){$cc_type = "MasterCard";} elseif($first_one==6){$cc_type = "Discover";} else {$cc_type = "Unknown";} //bla data $authxyz = "234"; $amount = "123.44"; Print " <center> <table width='800' height='50' cellspacing='0' cellpadding='0' border='1' bordercolor='black'> <tr valign='top'> <td width='200' height='10' align='left' valign='top'> <font face='Tahoma' size='2'>CARD TYPE</font> </td> <td width='200' height='10' align='left' valign='top'> <font face='Tahoma' size='2'>LAST 4</font> </td> <td width='200' height='10' align='left' valign='top'> <font face='Tahoma' size='2'>AUTH CODE</font> </td> <td width='200' height='10' align='left' valign='top'> <font face='Tahoma' size='2'>AMOUNT</font> </td> </tr> <tr valign='top'> <td width='200' height='40' align='left' valign='top'> <font face='Tahoma' size='2'>$cc_type</font> </td> <td width='200' height='40' align='left' valign='top'> <font face='Tahoma' size='2'>$last_four</font> </td> <td width='200' height='40' align='left' valign='top'> <font face='Tahoma' size='2'>$authxyz</font> </td> <td width='200' height='40' align='left' valign='top'> <font face='Tahoma' size='2'>$amount</font> </td> </tr> </table> </center> "; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2007 Share Posted December 18, 2007 <?php $number = "$cc_num"; $last_four = substr($number, -4); switch($number{1}) { case '3': $cc_type = 'American Express'; break; case '4': $cc_type = 'Visa'; break; case '5': $cc_type = 'MasterCard'; break; case '6': $cc_type = 'Discover'; break; default: $cc_type = 'Unknown'; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 You are forcing it to 3 everytime here if($first_one=3){$cc_type = 'American Express';} change to if($first_one==3){$cc_type = 'American Express';} Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted December 18, 2007 Author Share Posted December 18, 2007 Thanks for the help guys...it looks like I wasn't properly limiting the results. I was using substr($number, 1) when I should have been using substr($number,0,1) It works now. Here is the working code.. <?php $number = "$cc_num"; $last_four = substr($number, -4); $first_one = substr($number,0,1); echo $first_one; if($first_one=='3'){$cc_type = 'American Express';} elseif($first_one=='4'){$cc_type = 'Visa';} elseif($first_one=='5'){$cc_type = 'MasterCard';} elseif($first_one=='6'){$cc_type = 'Discover';} else {$cc_type = 'Unknown';} ?> Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2007 Share Posted December 18, 2007 Per my example, theres no need for substr at all. Quote Link to comment Share on other sites More sharing options...
xinteractx Posted December 19, 2007 Share Posted December 19, 2007 oh wow.. sorry i did not even see the logic flaws. I am so not use to short tagging.. <?=$amount?> .. maybe because I use php5 or something.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.