2011-02-03 2 views
0

나는 upc 데이터베이스에서 데이터를 검색 한 다음 데이터를 내 데이터베이스에 삽입하려고합니다. 모든 코드는 정확하지만 데이터베이스를 검사 할 때 내 데이터베이스 테이블에 레코드가 없습니다. 내 코드는 데이터 삽입 문제

if(!$resp->faultCode()) 
    { 
     //Store the value of the response in a variable 
     $val = $resp->value(); 
     //Decode the value, into an array. 
     $data = XML_RPC_decode($val); 
     //Optionally print the array to the screen to inspect the values 
       echo $upc=$data['upc']; 
       echo $ean=$data['ean']; 
       echo $description=$data['description']; 
       echo $size=$data['size']; 
       $query1="INSERT INTO upc(upc,ean,description,size) values('$upc','$ean','$description','$size')"; 
       var_dump($query1); 
       $result1=mysql_query($query1); 
입니다. 참고 사항 나는 모든 변수를 반향하고 결과는 다음과 같이 표시됩니다.
639382000393 
0639382000393 
The Teenager's Guide to the Real World by BYG Publishing 
book 
string(166) "INSERT INTO upc(upc,ean,description,size) values('639382000393 
','0639382000393 
','The Teenager's Guide to the Real World by BYG Publishing 
','book 
')" 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 's Guide to the Real World by BYG Publishing 
','book 
')' at line 1
데이터가 테이블에 삽입되지 않습니다.

+0

mysql_query는 무엇을 반환합니까? 'true' 또는'false'? mysql_query가'false '를 반환하면 항상 mysql_error로 에러 메시지를받을 수있다. – PatrikAkerstrand

+0

내 질문을 에러 – hunter

+0

으로 업데이트한다. 쿼리 결과를 확인한다. – Grumpy

답변

2

데이터 대신 바인드 변수를 사용하여, 당신은 당신의 쿼리를 만들어 함께 문자열을 매쉬업하는하는 ' 문자를 포함합니다. 문자열을 구분하는 데 '을 사용하므로 SQL이 중단됩니다. 이것은 또한 SQL Injection 공격에 취약하다는 것을 의미합니다.

bound variables을 사용하십시오.

+0

안녕하십니까. 보내려는 데이터를 보여주고 싶습니다. 그래서 json에서'$ json = array(); echo $ json [] = $ data; '하지만 아무 것도 페이지에 표시되지 않습니다. – hunter

1

물론 작동하지 않습니다. 문자열에 작은 따옴표가 있습니다. 줄을 벗어나면 괜찮을거야.

문자열 (166) "UPC 삽입 반 (UPC, EAN, 설명, 크기) 값 ('639382000393
', '0639382000393
을', '십대'BYG 게시하여 현실 세계의 가이드
는 ','책
')는 "