/    Sign up×
Community /Pin to ProfileBookmark

credit card validation

hey all, currently im having a serious problem with my codings. now im using java to do my credit card validation. everything looks fine but now the thing is i cannot connect to my database by using php. Can anyone help me check what’s wrong with my codings as soon as possible ? Thankz ^^.

“creditcard” table -> cardNumber (PK), cardType, cardMonth, cardYear, custID (FK)

<?php

include (“topbar.php”);

foreach($_POST as $varname => $value)
$formVars[$varname] = trim($value);

$query = “INSERT INTO creditcard set custID = -1,”.
“cardNumber =””. $formVars[“cardNumber”].””,”.
“cardType =””. $formVars[“cardType”].””,”.
“cardMonth =””. $formVars[“cardMonth”].””,”.
“cardYear =””. $formVars[“cardYear”].”””;

$mysql_result = mysql_query($query, $mysql_connection);

include (“dbdisconnect.php”);

?>
<html>
<SCRIPT LANGUAGE=JAVASCRIPT>

function validateForm()
{
var cardNumber = trimBetweenSpaces(trimBegEndSpaces(document.ccform.UMnumber.value));
var expire = trimBetweenSpaces(trimBegEndSpaces(stripOffNonDigit(document.ccform.UMexpirM.value + document.ccform.UMexpirY.value)));
}

function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
var ar = new Array( cardNumber.length );
var i = 0,sum = 0;

for( i = 0; i < cardNumber.length; ++i ) {
ar[i] = parseInt(cardNumber.charAt(i));
}
for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
ar[i] *= 2; // every second digit starting with the right most (check digit)
if( ar[i] > 9 ) ar[i]-=9; // will be doubled, and summed with the skipped digits.
} // if the double digit is > 9, ADD those individual digits together

for( i = 0; i < ar.length; ++i ) {
sum += ar[i]; // if the sum is divisible by 10 mod10 succeeds
}
return (((sum%10)==0)?true:false);
}

function expired( month, year ) {
var now = new Date(); // this function is designed to be Y2K compliant.
var expiresIn = new Date(year,month,0,0,0); // create an expired on date object with valid thru expiration date
expiresIn.setMonth(expiresIn.getMonth()+1); // adjust the month, to first day, hour, minute & second of expired month
if( now.getTime() < expiresIn.getTime() ) return false;
return true; // then we get the miliseconds, and do a long integer comparison
}

function validateCard(cardNumber,cardType,cardMonth,cardYear) {
if( cardNumber.length == 0 ) { //most of these checks are self explanitory
alert(“Please enter a valid card number.”);
document.ccform.cardNumber.focus == true;
return false;
}
for( var i = 0; i < cardNumber.length; ++i ) { // make sure the number is all digits.. (by design)
var c = cardNumber.charAt(i);

if( c < ‘0’ || c > ‘9’ ) {
alert(“Please enter a valid card number. Use only digits. Do not use spaces or hyphens.”);
document.ccform.cardNumber.focus == true;
return false;
}
}
var length = cardNumber.length; //perform card specific length and prefix tests

switch( cardType ) {
case ‘a’:

if( length != 15 ) {
alert(“Please enter a valid American Express Card number.”);
return false;
}
var prefix = parseInt( cardNumber.substring(0,2));

if( prefix != 34 && prefix != 37 ) {
alert(“Please enter a valid American Express Card number.”);
return false;
}
break;

case ‘m’:

if( length != 16 ) {
alert(“Please enter a valid MasterCard number.”);
return false;
}
var prefix = parseInt( cardNumber.substring(0,2));

if( prefix < 51 || prefix > 55) {
alert(“Please enter a valid MasterCard number.”);
return false;
}
break;
case ‘v’:

if( length != 16 && length != 13 ) {
alert(“Please enter a valid Visa Card number.”);
return false;
}
var prefix = parseInt( cardNumber.substring(0,1));

if( prefix != 4 ) {
alert(“Please enter a valid Visa Card number.”);
return false;
}
break;
}

if( !mod10( cardNumber ) ) { // run the check digit algorithm
alert(“Sorry! this is not a valid credit card number.”);
document.ccform.cardNumber.focus == true;
return false;
}

if( expired( cardMonth, cardYear ) ) { // check if entered date is already expired.
alert(“Sorry! The expiration date you have entered would make this card invalid.”);
document.ccform.cardNumber.focus == true;
return false;
}

else
{
alert (“Congratulations! Your credit card has been verified.”);
return true;
}
}

</SCRIPT>

<form name=”ccform” action=”confirmation.php” method=”POST” onSubmit=”return validateCard(this.cardNumber.value,this.cardType.value,this.cardMonth.value,this.cardYear.value);”>

<TABLE width=”530″ cellspacing=”0″ cellpadding=”0″>
<TR>
<TD align=”left” valign=”middle” nowrap><P>&nbsp;&nbsp;Card Type</P></TD>
<TD align=”left” valign=”middle” nowrap><P>:</P></TD>
<TD valign=”bottom” nowrap>
<SELECT name=”cardType”>
<OPTION value=”Select”> -Please Select-
<OPTION value=”a”> American Express
<OPTION value=”m”> MasterCard
<OPTION value=”v”> Visa
</SELECT>
</TD>
</TR>
<td>&nbsp;</td>
<TR>
<TD align=”left” valign=”middle” nowrap><P>&nbsp;&nbsp;Card Number</P></TD>
<TD align=”left” valign=”middle” nowrap><P>:</P></TD>
<TD valign=”bottom” nowrap>
<P><INPUT type=”Text” name=”cardNumber” size=”17″ maxlength=”16″> example: <FONT size=-1><I>( 1234567890123456 )</I></I></FONT></P>
</TD>
</TR>
<td>&nbsp;</td>
<TR>
<TD align=”left” valign=”middle” nowrap><P>&nbsp;&nbsp;Expiration Date</P></TD>
<TD align=”left” valign=”middle” nowrap><P>:</P></TD>

<TD valign=”bottom” nowrap>
<P>
<SELECT name=”cardMonth”>
<OPTION value=”01″> 01
<OPTION value=”02″> 02
<OPTION value=”03″> 03
<OPTION value=”04″> 04
<OPTION value=”05″> 05
<OPTION value=”06″> 06
<OPTION value=”07″> 07
<OPTION value=”08″> 08
<OPTION value=”09″> 09
<OPTION value=”10″> 10
<OPTION value=”11″> 11
<OPTION value=”12″> 12
</SELECT>
<SELECT name=”cardYear”>
<OPTION value=”2005″> 05
<OPTION value=”2006″> 06
<OPTION value=”2007″> 07
<OPTION value=”2008″> 08
<OPTION value=”2009″> 09
<OPTION value=”2010″> 10
<OPTION value=”2011″> 11
<OPTION value=”2012″> 12
<OPTION value=”2013″> 13
<OPTION value=”2014″> 14
<OPTION value=”2015″> 15
<OPTION value=”2016″> 16
<OPTION value=”2017″> 17
<OPTION value=”2018″> 18
<OPTION value=”2019″> 19
<OPTION value=”2020″> 20

</SELECT>
example: <FONT size=-1><I>( MM YY )</I></I></FONT>
</P>
</TD>
</TR>

<td>&nbsp;</td>
<tr>
<TD align=”left” valign=”middle” nowrap><P>&nbsp;&nbsp;Deposit</P></TD>
<TD align=”left” valign=”middle” nowrap><P>:</P></TD>

<TD valign=”bottom” nowrap>
<P>&nbsp;S$10</p>
</TD>
</TR>
<td>&nbsp;</td>

<TR>
<TD align=middle colSpan=3><INPUT type=submit value=Submit name=submit> <INPUT type=reset value=Reset> </TD></TR></TBODY></TABLE></FORM>
<td width=”166″>

<table height=”540″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”166″ height=”266″ valign=”top”><br>
<img src=”../images/ktv_comp.jpg” width=”145″ height=”247″></td>
</tr>
<tr>
<td height=”190″ valign=”top”><img src=”../images/karaoke.jpg” width=”145″ height=”190″ align=”top”></td>
</tr>
<tr>
<td height=”80″ valign=”top”> <img src=”../images/banner_120x60.gif” width=”145″ height=”80″></td>
</tr>
</table></td>
</tr>

</BODY>
</HTML>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 06.2006 — Where do you do your mysql_connect()?
×

Success!

Help @violetng85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...