I am having trouble getting teh results i want from this mysql query. And i think the trouble lies in this line of code:
$group=”SELECT * from mybb_users where usergroup AND additionalgroups = ‘$usergroup'”;
because i noticed that the additionalgroups column in the database has more than one value separated by a comma(,) whereas the usergroup only has ONE value. Here is a screenshot:
here is an image: https://i.stack.imgur.com/HVVN9.jpg
The entire code works perfect if i remove the additionalgroups column from the code and only check the usergroup column, but that is not what i want 🙁 Below is the entire code:
// Connect to server and select databse.
mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect to mysql");
mysql_select_db("$db_name")or die("cannot select DB");
$id=$_GET['lid']; // Get lid from URL
$usergroup =$_GET['game']; // Get the usergroup/game from the URL
// Check to see if the user is a VIP Member and fetch them.
$group="SELECT * from mybb_users where usergroup AND additionalgroups = '$usergroup'";
$group2=mysql_query($group) or die("Could not get users");
while($raw=mysql_fetch_array($group2))
{
// Fetch all UserIDs of the VIP members and match them with the UfID (in the userfields table)
$userid = $raw['uid'];
$group3="SELECT * from mybb_userfields where ufid = '$userid'";
$group4=mysql_query($group3) or die("Could not match userid");
while($raw=mysql_fetch_array($group4))
{
// assigns a lid from the vip members to the variable $lid
$lid = $raw['fid7'];
// Display the hash of the lid if it matches with the lid from the URL
if($lid == '')
{
}
elseif($lid == $id)
{
echo "[key]{$lid};";
}
else
{
}
}
}
I’m not sure about
where usergroup AND ...– isusergroupa DB field? Anyway, you could do it withBut that is not enough yet. AFAICS you are vulnerable to SQL injection. Please use
mysql_real_escape()at the right places, namely everywhere you put variables with user input into a SQL query.