I want to set up routine that assigns a new user a unique group number during registration. I've tried to piece together other suggestions but have failed to come up with a working solution. The goal is that each new registered user will have a ugroup_id in the user table that increases by one number from the previous highest group__id. This way the users (who will be administrators of their own groups) can pass on their assigned ugroup_id to any additional users they create inside the application.
Here is where I am so far
BEFORE REGISTRATION EVENT
global $conn;
$maxg = "SELECT max(ugroup_id) as mx from user ";
$group = "mx"+1;
$values["ugroup_id"]=group;
db_exec($maxg,$conn);