prooi Posted September 23, 2011 Share Posted September 23, 2011 (edited) Hello guys. I would like some feedback on my hook script, to see if it looks just a bit right. So here goes: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databasename", $con); function add_user_to_group($vars) { mysql_query("UPDATE tblclients SET groupid = 2 WHERE id = ". $vars['id'] .""); } add_hook("ClientAdd",1,"add_user_to_group"); mysql_close($con); ?> What I would like this script to do, is to add all new clients to a specific usergroup. Regards, Frederik Nielsen Edited September 23, 2011 by prooi Edited the script a bit 0 Quote Link to comment Share on other sites More sharing options...
Andrey.L Posted September 23, 2011 Share Posted September 23, 2011 in hooks do not need to open and close connection to mysql as connection is already open by whmcs 0 Quote Link to comment Share on other sites More sharing options...
prooi Posted September 23, 2011 Author Share Posted September 23, 2011 Okay, so the connect part could be removed. So this script would do it? <?php function add_user_to_group($vars) { mysql_query("UPDATE tblclients SET groupid = 2 WHERE id = ". $vars['id'] .""); } add_hook("ClientAdd",1,"add_user_to_group"); ?> 0 Quote Link to comment Share on other sites More sharing options...
Andrey.L Posted September 23, 2011 Share Posted September 23, 2011 $vars['userid'] instead of $vars['id'] Otherwise, all right. 0 Quote Link to comment Share on other sites More sharing options...
prooi Posted September 23, 2011 Author Share Posted September 23, 2011 Cool. Thanks for the quick responses. 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.