Page 1 of 1

More help with php & mySql

Posted: Thu Mar 23, 2006 6:15 am
by Kofikoduah
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.

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; 
} 
?>
the question thus remains do i use

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.

Posted: Thu Mar 23, 2006 6:21 am
by Benjamin

Code: Select all

ini_set('mysql.default_host', 'localhost');
ini_set('mysql.default_user', 'username');
ini_set('mysql.default_password', 'password');

define ("DatabaseName", "dbname");

function CreateDatabaseConnection()
  {
  $LinkId = mysql_connect();
  mysql_select_db(DatabaseName, $LinkId);
  return $LinkId;
  }

$LinkId = CreateDatabaseConnection();


$query = "select op_card_number from op_members where op_card_number='" . $op_card_number . "'";

$Data = mysql_fetch_assoc(mysql_query($query,$LinkID));

echo $Data['op_card_number'];
I'm not sure what your trying to get out of the db but that might help you.

Posted: Thu Mar 23, 2006 6:31 am
by Kofikoduah
if you could kindly look back to an earlier post this morning, it would explain what i am trying to achieve

viewtopic.php?t=45949&sid=0eea87237771f ... 75e6b34ebb

thank you