valerif, on 03 September 2009, 12:02, said:
I have one problem though. This the message I get when trying to send a voucher to another account after purchasing it:
Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in /homepages/.../includes/functions/database.php on line 113
I found a similar problem when installing this contribution on a clients store.
The solution I found was to change the code around line #65 of gv_send.php
Search for
$insert_id = tep_db_insert_id($gv_query);
$gv_query=tep_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, sent_lastname, emailed_to, date_sent) values ('" . $insert_id . "' ,'" . $customer_id . "', '" . addslashes($gv_customer['customers_firstname']) . "', '" . addslashes($gv_customer['customers_lastname']) . "', '" . $HTTP_POST_VARS['email'] . "', now())");
and replace it with
$gv_query=tep_db_query("select coupon_id from " . TABLE_COUPONS . " where coupon_code = '" . $id1 . "'");
$gv_new_coupon=tep_db_fetch_array($gv_query);
$gv_query=tep_db_query("insert into " . TABLE_COUPON_EMAIL_TRACK . " (coupon_id, customer_id_sent, sent_firstname, sent_lastname, emailed_to, date_sent) values ('" . $gv_new_coupon['coupon_id'] . "' ,'" . $customer_id . "', '" . addslashes($gv_customer['customers_firstname']) . "', '" . addslashes($gv_customer['customers_lastname']) . "', '" . $HTTP_POST_VARS['email'] . "', now())");
I got the feeling that
tep_db_insert_id($gv_query) was the cause of the problem, and I didn't want to edit the .../include/database.php in case other parts of osCommerce relied on it's current functionality, so I ended up getting the coupon information from the coupons file and then inserting a record in the email track table.
I also found that the remote IP wasn't being entered into the redeem track table so made the following change in gv_redeem.php around line #52
Search for
// Update redeem status
$gv_query = tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
and replace it with
// Update redeem status
$gv_query = tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $customer_id . "', now(),'" . $_SERVER['REMOTE_ADDR'] . "')");
I believe the reason it wasn't working for me is that
$REMOTE_ADDR requires register_globals to be on, so I used the super global
$_SERVER['REMOTE_ADDR'] instead.
Best regards