Results 1 to 2 of 2

Thread: Help: custom voucher code module

  1. #1
    Join Date
    Oct 2011
    Posts
    14

    Default Help: custom voucher code module

    Hi,

    I am coding a voucher code module but im encountering some problems with CreateAccount() function.
    1. The function of the module it to create a voucher code then saving those code to the remote database. The quantity of the voucher code depends on what the client enter in the configurable option named "Voucher Quantity".
    2. However, the problem is that It is not saving at all to the database and no voucher code is generated. Also, I doubt the looping is correct also.

    3. Some small help would be greatly appreciated.

    Below is the custom function and createAccount() function:

    PHP Code:
    function voucher_ConfigOptions() {

        
    # Should return an array of the module options for each product - maximum of 24

        
    $configarray = array(
         
    "Database Hostname"     => array( "Type" => "text",     "Size" => "35", ),
         
    "Database Name"         => array( "Type" => "text",     "Size" => "35", ),
         
    "Database Username"     => array( "Type" => "text",     "Size" => "35", ),
         
    "Database Password"     => array( "Type" => "password""Size" => "35", ),
         
    "Voucher Qty"            => array( "Type" => "text",     "Size" => "35", ),
        );

        return 
    $configarray;

    }


    function 
    voucher_CreateAccount($params) {
        
        
    # Connect to remote MySQL database
        
    $link mysql_connect($params["configoption1"], $params["configoption3"], $params["configoption4"]);
        if (!
    $link) {
            return 
    'Could not connect to MySQL';
        }
        
        
    # Select DB
        
    $db_select mysql_select_db($params["configoption2"], $link);
        if (!
    $db_select) {
            return 
    'Could not select database';
        }

    $i 1;
        while(
    $i <= $params['configoptions'][$result_row['Voucher Quantity']])
        {
            
                
    $voucher_code voucher_vouchercode() . '-' voucher_vouchercode() . '-' voucher_vouchercode();
                
    //$result = $db->sql_query("SELECT code_name FROM vouchers WHERE code_name='$gen'");
                //$chk = $db->sql_numrows($result);
                    
    $sql mysql_query("INSERT INTO `vouchers` (`code_name`, `duration`) VALUES('".$voucher_code."', '2592000')"$link);
                    if (!
    $sql) {
                        return 
    'Could not insert row into database '.mysql_error($link);
                    }
                    break;
            
        
    $i++;
        }
    return 
    'success';

    }

    function 
    voucher_vouchercode() {
        
    $chars "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        
    mt_srand((double)microtime()*1000000);
        
    $i 0;
        while (
    $i <= 4)
        {
            
    $num mt_rand() % 33;
            
    $tmp substr($chars$num1);
            
    $pwd $pwd $tmp;
            
    $i++;
        }
        return 
    $pwd;


  2. #2
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    1,680

    Default

    Your while loop is all jacked up.

    Code:
    for ($i=0; $i < (int)$params["configoption5"]; $i++) {
      // do stuff here
    }

Similar Threads

  1. Good example of return EPP code in custom registrar module?
    By ptomter in forum Customisation and Integration Questions
    Replies: 0
    Last Post: 08-24-12, 11:27 PM
iron-diatonic