I would like to get the affiliate id by using the username from database (all data were created already). Say when someone click on the following link: www.xx.com/yy.php?id=[whatever the username is] I can display in content with <?$q2[affiliateid]?> to show his/her affiliateid. Here is part of the code: $q2 = mysql_query("SELECT AffiliateID FROM Affiliates WHERE Username = $id"); if (!$row2 = mysql_fetch_array($q2)) { print (mysql_error()); } The above code is not working properly, but I was able to display the username correctly if the link is www.xx.com/yy.php?id=[affiliateid] (when I change the code) One more thing: If I change the code to $q2 = mysql_query("SELECT AffiliateID FROM Affiliates WHERE Username = 'rath12343' <===[one of the username on database]"); everything works perfectly. What did I do wrong here? Any idea?