2016-10-24 2 views
-3

아래 오류가 나타납니다. MySQL과 PHP를 사용하여 키워드를 검색하여 데이터베이스에서 값을 가져와야합니다.PHP와 MySQL을 사용하여 데이터베이스에서 데이터를 가져 오는 동안 Sql 구문 오류가 발생합니다.

Error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sheela'%' and b.quadrant='2' and b.status=1 and b.city !=0 ORDER BY b.member_id ' at line 1

내 쿼리는 아래에 나와 있습니다.

$searchKey=$_GET['searchKey']; 
$day_id=$_GET['day_id']; 
$quad_id=explode(",",$_GET['quad_id']); 
$keyword = '%'.$searchKey.'%'; 
"SELECT b.member_id,b.rest_name,b.proviance,b.city,b.postal,b.address,b.country,b.person,b.mobile,b.url,b.status,b.premium,b.image,b.business_phone_no,b.email,b.multiple_image,b.quadrant,ct.city_id,ct.city_name FROM db_restaurant_basic AS b INNER JOIN db_city AS ct ON b.city=ct.city_id WHERE b.rest_name LIKE '".$keyword."' and b.quadrant='".$quad_id[$i]."' and b.status=1 and b.city !=0 ORDER BY b.member_id DESC. 

이 오류를 해결하는 데 도움을주십시오.

답변

0

구문이 잘못되었습니다. Sheela은 작은 따옴표로 포함되어야합니다 :

... WHERE b.rest_name LIKE '%Sheela%' and ... 

UPDATE : 당신이 당신의 질문을 updaing 후보기 trhe 쿼리에서

, 당신은 문제를 만드는 당신의 변수에 singlequote 있습니다.

당신은 방지하기 위해 준비 statemens를 사용해야합니다 그것을

+0

내가 같이가 'WHERE b.rest_name LIKE ' ". $ keyword."''. – subhra

+0

@subhra하지만 코드에는 표시되지 않습니다. 당신이 보인 경우에, sheela는 문자열이 아니라 변수입니다 – Jens

+0

@ jens : 업데이트 된 게시물을 확인하십시오. – subhra

0

를 사용하여 아래와 같이 데이터베이스 쿼리 및 쿼리 데이터 준비에 적절한 견적 및 따옴표 ...

$searchKey=$_GET['searchKey']; 
$day_id=$_GET['day_id']; 
$quad_id=explode(",",$_GET['quad_id']); 
$keyword = "'%".$searchKey."%'"; 
"SELECT b.member_id,b.rest_name,b.proviance,b.city,b.postal,b.address,b.country,b.person,b.mobile,b.url,b.status,b.premium,b.image, 
b.business_phone_no,b.email,b.multiple_image,b.quadrant,ct.city_id,ct.city_name 
FROM db_restaurant_basic AS b 
INNER JOIN db_city AS ct ON b.city=ct.city_id 
WHERE 
b.rest_name LIKE ".$keyword." and b.quadrant='".$quad_id[$i]."' and b.status=1 and b.city !=0 ORDER BY b.member_id DESC. 
+0

처럼 "업데이트"아래에 새 정보를 추가해야합니다. 업데이트 된 게시물을 확인하십시오. – subhra

+0

또한 오류가 발생합니다. – subhra

+0

질문을 업데이트했기 때문에 업데이트 된 답변을 참조하십시오 .... –

관련 문제