function leavegroup($uid, $gid) { //check if joined if (checkjoin($uid, $gid)) { //remove as a group member $q = "DELETE FROM `group_members` WHERE `group_members`.`uid` = {$uid} AND `group_members`.`gid` = {$gid}"; mysql_query($q) or die('leavegroup sqlerr1'); //decrement member count in group $q = "SELECT `members` FROM `groups` WHERE `id`={$gid}"; $result = mysql_query($q) or die('leavegroup sqlerr2'); $row = mysql_fetch_array($result); $mem = $row['members'] - 1; $q = "UPDATE `groups` SET `members` = '{$mem}' WHERE `groups`.`id` ={$gid}"; $result = mysql_query($q) or die('leave group sqlerr3'); } else { error('You are not a member of this group !!'); } }
<?php if (checkjoin($uid, $gid)) { ?> <font color="#666666" size="-1">Joined</font> ( <font size="-2"><a href="index.php?option=com_content&view=article&id=30&gid=<?php echo $gid; ?> &action=leave" style="text-decoration:none">Leave Group</a></font> ) <?php } else { ?> <form id="form2" name="form2" method="post" action="index.php?option=com_content&view=article&id=30&gid=<?php echo $gid; ?> "> <label> <input type="submit" name="join" id="button2" value="Join group" /> </label> </form> <?php } ?> <a data-lightbox="width:1000;height:700" href="kart/contact.php?aid=<?php echo $ad['id']; ?> " class="myButton">Contact Seller</a></td>