Jump to content

Hook Username error


Recommended Posts

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");

 

?>

Link to comment
Share on other sites

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");

 

?>

Link to comment
Share on other sites

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');

?>

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