2011-02-03 139 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 2011-02-03 11:44:17

+0

我更新我的問題,錯誤 – hunter 2011-02-03 11:51:28

回答

2

的數據包括'性格和,而不是使用綁定變量,你只是糖化串在一起,以創建查詢。由於您使用'來分隔字符串,因此SQL會中斷。這也意味着您很容易受到SQL注入攻擊。使用bound variables

1

當然,它不起作用。你的字符串中有單引號。逃避絃樂,你會沒事的。

串(166)「INSERT INTO UPC(UPC,EAN,說明,大小)VALUES( '639382000393
', '0639382000393
',「的青少年指南到真實世界的BYG出版社
「」書
「)」