More help with php & mySql
Posted: Thu Mar 23, 2006 6:15 am
Ok, thanx for the repy, i'm basically starting an online service in my country where registered users can purchase goods online from member merchants of the service. Currently no such thing exists in my country.
Basically $output4capture is what is generated and i need it to be sent to a database along with other user details. The only thing is that this is a behind the scene operation which the user never notices until his details are emailed and card with the generated number is posted to him/her. so as originally stated, i want to validate the generated number against vaild entries in the database for duplicates. The generation process a function which can be called again if the number already exists.
the question thus remains do i use
?
how would i build a full query for the above code which will do the database checking?
the table is called op_members field is op_card_number
Please Help.
Basically $output4capture is what is generated and i need it to be sent to a database along with other user details. The only thing is that this is a behind the scene operation which the user never notices until his details are emailed and card with the generated number is posted to him/her. so as originally stated, i want to validate the generated number against vaild entries in the database for duplicates. The generation process a function which can be called again if the number already exists.
Code: Select all
<?
function generate_Ashanti(){
//---------Defines Onpay Cards-----------------
//15-digit cards, Arranged by Geographic Location in Ghana
//Ashanti Region
$onpayPrefixList[] = "2029";
$onpayPrefixList[] = "3029";
/*
'prefix' is the start of the number as a string, any number of digits.
'length' is the length of the number to generate. Typically 15 or 16
*/
function completed_number($prefix, $length) {
$ccnumber = $prefix;
# generate digits
while ( strlen($ccnumber) < ($length - 1) ) {
$ccnumber .= rand(0,9);
}
# Calculate sum
$sum = 0;
$pos = 0;
$reversedCCnumber = strrev( $ccnumber );
while ( $pos < $length - 1 ) {
$odd = $reversedCCnumber[ $pos ] * 2;
if ( $odd > 9 ) {
$odd -= 9;
}
$sum += $odd;
if ( $pos != ($length - 2) ) {
$sum += $reversedCCnumber[ $pos +1 ];
}
$pos += 2;
}
# Calculate check digit
$checkdigit = (( floor($sum/10) + 1) * 10 - $sum) % 10;
$ccnumber .= $checkdigit;
return $ccnumber;
}
function credit_card_number($prefixList, $length, $howMany) {
for ($i = 0; $i < $howMany; $i++) {
$ccnumber = $prefixList[ array_rand($prefixList) ];
$result[] = completed_number($ccnumber, $length);
}
return $result;
}
function output($title, $numbers) {
$result[] = "<div class='ONPAYNumbers'>";
$result[] = "<h3>$title</h3>";
$result[] = implode('<br />', $numbers);
$result[]= '</div>';
return implode('<br />', $result);
}
#
# Main
#
echo "<div class='creditCardSet'>";
$onpay = credit_card_number($onpayPrefixList, 15, 1);
$out4capture = output("ONPAY CARD FOR ASHANTI REGION", $onpay);
//----Print's the generated number on screen
echo $out4capture;
}
?>Code: Select all
SELECT 1 FROM `table` WHERE `field` = '{$out4capture}'how would i build a full query for the above code which will do the database checking?
the table is called op_members field is op_card_number
Please Help.