2011-08-14 5 views
1

이 mysql 쿼리에서 원하는 결과를 얻는데 문제가 있습니다. 그리고 문제는이 코드 줄에 있다고 생각합니다 :빈 결과를 얻지 않고이 mysql 쿼리를 어떻게 작동시킬 수 있습니까?

$ group = "mybb_users에서 SELECT * usergroup 및 additionalgroups = '$ usergroup'";

데이터베이스의 additionalgroups 열에 둘 이상의 값이 쉼표 (,)로 구분되어 있기 때문에 usergroup에 하나의 값만있는 것으로 나타났습니다. 여기

이미지입니다 : 여기에 스크린 샷입니다 http://i.imgur.com/UTbmX.jpg

내가 코드에서 additionalgroups 열을 제거하고 오직 사용자 그룹 열을 확인하지만 내가 아래 :(원하는없는 경우 전체 코드가 완벽하게 작동 전체 코드입니다. 확인하는 방법에

// 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 
{ 
} 
} 

} 
+1

'$ usergroup'은 사용자가 제공 한 입력에서 직접 가져 오지만 위생적으로 처리하지는 않습니다. 입력 내용을 삭제하십시오. http://php.net/manual/en/function.mysql-real-escape-string.php –

답변

1

내가를 확실하지 않다- usergroup DB 필드입니까? 어쨌든, 당신은 할 수있어

$group="SELECT * from mybb_users where usergroup AND FIND_IN_SET('$usergroup', additionalgroups) != 0; 

그러나 아직 충분하지 않습니다. AFAICS 당신은 SQL 주입에 취약합니다. 올바른 위치에 mysql_real_escape()을 사용하십시오. 즉, SQL 쿼리에 사용자 입력이있는 변수가있는 모든 곳에서 사용하십시오.

+0

좋아,'FIND_IN_SET()'이 내 솔루션보다 훨씬 낫다. 하지만 주사 사물은 여전히 ​​적용됩니다 ... – glglgl

+0

나는 당신의 방법을 시도했습니다 ... 작동하지 않을 것입니다 그리고 usergroup은 DB 칼럼이고 $ usergroup은 URL에서 [game] vaule을 가져 오는 변수입니다 – Ash

+0

무슨 뜻 " "작동하지 않을까요? mysql_error()에 의해 표시되는 MySQL 에러는 무엇입니까? 아니면 결과가 비어있는 것입니까? 내가 FIND_IN_SET을 시도 – glglgl

4

가 FIND_IN_SET 기능이다는

SELECT * from mybb_users where usergroup AND FIND_IN_SET('$usergroup', additionalgroups) != 0 
+0

+1. 나는 너무 늦게 도착했다. :) –