PDA

View Full Version : Update Usergroup using Php Script if email already exist


warmarks
08-03-2012, 11:14 AM
Hi,

I am trying to update usergroup of a given user whose email is known in $email variable.

<?php
define('VB_AREA', 'External');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_USERINFO', 1);
define('CWD', '/home--path');
require_once(CWD . '/includes/init.php');
// Data from Form Submision for VB


$email = $_GET["email"];
$usrgrp = $_GET["usergroupid"];





Can you please guide me what code i need to add in there...
so that if a user with $email is member of any usergroup before, i can add him to usergroup 3
also when $usrgrp=3,

i mean i know the email of the useraccount, and want to add him to additional usergroup (not removing from the existing ursergroups) i am using above php code from a non-vb page.

Looking forward to receive some help in this regard.

Thank you!

kh99
08-03-2012, 10:46 PM
What you want to do is update the membergroupids field in the user table, where the email field matches the email address you have. The membergroupids field is a comma-separated list of integers (groupids), so you might be able to do it with one UPDATE query (which would probably need an "if" in the query because you'd need a comma or not depending on whether the membergroupids field is empty). If you wanted to do "right", you'd probably want to read the field, explode it in to an array, add "3" if it's not already in the array, then implode it back to a list and do an update. (I looked in to it before and found that the vb code is pretty forgiving of what's in that field, so you you wanted to just add 3 to the list without checking for it already being there, it should work anyway).