0

自从我成为一名编码员以来已经有很长一段时间了,我正在准备一些我知道非常简单的东西。

我正在尝试访问产品的 XML 页面并将它们插入到我的数据库中。

我生成的代码给了我以下错误消息:

Unknown column '10074' in 'field list'  

10074 是第一项的产品 ID。

代码如下。

你能指出我正确的方向吗,因为它真的很接近我。

提前谢谢了!

<?php
   $Products = simplexml_load_file('http://atsdistribution.co.uk/feeds/xml_all_products.aspx');


$con = mysql_connect(*****);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("catflaps_products", $con);


foreach($Products->Product as $Product)
{
$ProductID = $Product->ProductID;
$Name = $Product->Name;
$DropshipPrice = $Product->DropshipPrice;
$SRP = $Product->SRP;
$Brand = $Product->Brand;
$Xline = $Product->Xline;
$InStock = $Product->InStock;
$Stock = $Product->Stock;
$Barcode = $Product->Barcode;
$Weight = $Product->Weight;
$CategoryID = $Product->CategoryID;
$Category = $Product->Category;
$SmallImage = $Product->SmallImage;
$LargeImage = $Product->LargeImage;
$Description = $Product->Description;

mysql_query("INSERT INTO test(ProductID, Name, DropshipPrice, SRP, Brand, Xline, InStock, Stock, Barcode, Weight, CategoryID, Category, SmallImage, LargeImage, Description)
VALUES(`$ProductID`, `$Name` , `$DropshipPrice`, `$SRP`, `$Brand`, `$Xline`, `$InStock`, `$Stock`, `$Barcode`, `$Weight`, `$CategoryID`, `$Category`, `$SmallImage`, `$LargeImage`, `$Description`)")
        or die(mysql_error());

}

mysql_close($con);
// some code

?>
4

2 回答 2

0

您正在使用“反引号”(`)来引用您的值,因此 MySQL 将它们视为“列名”。使用常规的“单”引号 (') 应该可以解决您的问题

于 2013-03-24T18:31:22.590 回答
0

很可能是 xml 的解析。确保调用 mysql_real_escape_string 来清理数据。

http://php.net/manual/en/function.mysql-real-escape-string.php

于 2013-03-24T18:27:07.113 回答