If I understood it:
First, create an usergroup in vBulletin that has the priviliges you want.
Then (I assume you're checking aganist valid id in your script), do your checking. If it's valid go like this:
PHP Code:
// id of the group which user will be added to
$user_group_id = 5;
// id of the user that will be added to the group
$affected_user_id = 1;
$sql_query = "UPDATE user SET membergroupids = CONCAT(membergroupids, ',{$user_group_id}') WHERE userid = '{$affected_user_id}';";
Of course you have to adjust it to your needs.
You can check the member group id in CP, under Usergroups -> Usergroups manager.
Remember that you will need to connect to database which vBulletin forum is using, otherwise code will not work.