webmaster@auses.org.au Posted May 1, 2012 Share Posted May 1, 2012 Hi Folks, Newbie warning! I'm using whmcs for a membership billing system and trying to get the product 'username' to increment automatically with each new registrant. whmcs support said to add a hook AfterShoppingCartCheckout and here is my code. It is causing a white screen on all whmcs pages : ( Any thoughts on the solution? <?php /* Create username in incremental series */ function hook_create_username_action($vars) { $orderid = $vars['orderid']; $username = $vars['username']; $baseval = 20000 # Lowest member number value $result = mysql_query( SELECT id FROM tblhosting WHERE $orderid ); $username = $id + $baseval; mysql_query("UPDATE tblhosting SET username = $username WHERE id = $id"); } add_hook("AfterShoppingCartCheckout",1,"hook_create_username_action"); ?> 0 Quote Link to comment Share on other sites More sharing options...
webmaster@auses.org.au Posted May 1, 2012 Author Share Posted May 1, 2012 ok, that was rubbish, i admit it. I fixed the syntax errors in 2 minutes with debog on. Hope it works now... <?php /* Create username in incremental series */ function hook_create_username_action($vars) { $orderid = $vars['orderid']; $username = $vars['username']; $baseval = 20000; $result = mysql_query('SELECT id FROM tblhosting WHERE $orderid'); $username = $id + $baseval; mysql_query('UPDATE tblhosting SET username = $username WHERE id = $id'); } add_hook("AfterShoppingCartCheckout",1,"hook_create_username_action"); ?> 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted May 2, 2012 Share Posted May 2, 2012 Well, you're still not there. mysql_query only returns a result set object. You need to pass that to mysql_fetch_array() or mysql_fetch_assoc() to get the data. But since you only need to return 1 value from 1 row, its best to use get_query_val() as thats exactly what its designed to do. Also you should make use of the SQL Helper Functions whenever possible. Heres some updated code that should do what you want (untested) <?php function hook_create_username_action($vars) { $orderid = $vars['orderid']; $baseval = 20000; $id = get_query_val('tblhosting', 'id', 'orderid='.(int)$orderid); $username = $id + $baseval; update_query('tblhosting', array('username'=>$username), array('id'=>$id)); } add_hook('AfterShoppingCartCheckout', 999, 'hook_create_username_action'); ?> 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.