2011-02-03 146 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出版社
“”书
“)”