xauen Posted May 4, 2012 Share Posted May 4, 2012 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: 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, $num, 1); $pwd = $pwd . $tmp; $i++; } return $pwd; } 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted May 4, 2012 Share Posted May 4, 2012 Your while loop is all jacked up. for ($i=0; $i < (int)$params["configoption5"]; $i++) { // do stuff here } 0 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.