Fearghal Posted January 18, 2012 Share Posted January 18, 2012 I am writing some hooks to expand my new website, however the script is not working. I cannot see any errors, just no results. Is there an error log I can look at to see the problem? It's currently installed as an addon module and is supposed to run after module create. Any help would be appreciated! 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 18, 2012 Share Posted January 18, 2012 you can add logging code to your hook using the logActivity() function. Or, depending on what hook you're using, display the issue on the page using var_dump()'s. Or, you can use the output buffer functions to write output to a log file. 0 Quote Link to comment Share on other sites More sharing options...
Fearghal Posted January 18, 2012 Author Share Posted January 18, 2012 Thanks! I've now managed to work out that for some reason the variables are not being defined. I have... <?php function hook_updatetokens($vars) { $serviceid = $vars['serviceid']; $product = $vars['pid']; $username = $vars['username']; if($product==5){ $result = mysql_query("SELECT userid FROM tbl WHERE id=$serviceid"); $data = mysql_fetch_array($result); $userid= $data[0]; $smartyvalues["userid"] = $userid; //current credits $result = mysql_query("SELECT smscredits FROM tblclients WHERE id=$userid"); $data = mysql_fetch_array($result); $smscredits = $data[0]; $smartyvalues["smscredits"] = $smscredits; //New credit amount $newamount = $smscredits + 1; mysql_query("UPDATE `tblclients` SET `smscredits`='$newamount' WHERE `id`=$userid"); mysql_query("UPDATE `tblclients` SET `userid`='9' WHERE `id`=$userid"); }; } add_hook("AfterModuleCreate",1,"hook_updatetokens"); ?> Have I done something silly? 0 Quote Link to comment Share on other sites More sharing options...
k1ng440 Posted January 23, 2012 Share Posted January 23, 2012 (edited) <?php function hook_updatetokens($vars) { $serviceid = $vars['serviceid']; $product = $vars['pid']; $products = array(5,6,7,8,9); // products list if(in_array($product, $products) === true){ mysql_query("UPDATE `tblclients` SET `smscredits`= smscredits+1 WHERE `id` = (SELECT userid FROM tblhosting WHERE id = '{$serviceid}')"); // better } } add_hook("AfterModuleCreate",1,"hook_updatetokens"); ?> i didnt test it but its should work Edited January 23, 2012 by k1ng440 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 23, 2012 Share Posted January 23, 2012 $result = mysql_query("SELECT userid FROM tbl WHERE id=$serviceid"); There is no table called "tbl" 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted January 23, 2012 Share Posted January 23, 2012 Heres the full code that will probably work. <?php function hook_updatetokens($vars) { $serviceid = $vars['serviceid']; $product = $vars['pid']; $username = $vars['username']; if ($product == 5) { $query = "SELECT c.user, c.smscredits FROM tblclients c, tblhosting h WHERE h.id = $serviceid AND h.userid = c.id"; $result = full_query($query); $data = mysql_fetch_array($result); $userid = $data[0]; $smscredits = $data[1]; $smartyvalues["userid"] = $userid; $smartyvalues["smscredits"] = $smscredits; //New credit amount $newamount = $smscredits + 1; update_query("tblclients", array("smscredits"=>$newamount), array("id" => $userid)); } } add_hook("AfterModuleCreate",1,"hook_updatetokens"); ?> 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.