Jump to content

Trouble with mysql queries in ActionHooks


laszlof

Recommended Posts

Hey, I'm having a little trouble with an addon I'm working on. I cant seem to get mysql queries to work properly within some action hook code.

 

Does anyone have any ideas?

 


<?php

function verify_affiliate_coupon($vars) {
       if (isset($_SESSION['cart']['promo'])) {
               error_log("PROMO CODE SET IN CART!");
               $promocode = $_SESSION['cart']['promo'];
               $sql = "SELECT aff_id FROM `affcoupons` WHERE coupon='$promocode'";
               $data = mysql_query($sql);
               if (mysql_num_rows($data) > 0) {
                       while ($row = mysql_fetch_array($data)) {
                               $affid = $row[0];
                       }
                       error_log("AFFILIATE ID FOUND");
                       $_COOKIE['WHMCSAffiliateID'] = $affid;
                }
       }

}

add_hook("PreShoppingCartCheckout",1,"verify_affiliate_coupon","");

?>

 

Its throwing back an error that says the $data is not a valid mysql resource for mysql_num_rows. If I remove the row count checking, it tells me the same thing for mysql_fetch_array. Anyone have any clues?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated