0
我试图从Web上的XML文件中将数据导入到我的数据库中,以便我可以使用它。将XML文件中的数据插入到表中
我已经生成了以下代码,但是由于我已经完成了很长时间的编码工作,所以我收到了错误消息。
错误是“字段列表”中的“未知列'10074'”。
10074是XML文件中第一项的产品ID。
任何指针都会非常有用,因为它正在做我的头!
我的代码如下:
<?php
$Products = simplexml_load_file('http://atsdistribution.co.uk/feeds/xml_all_products.aspx');
$con = mysql_connect(Details);
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);
?>
太谢谢你了!这真是一种魅力! 我已经离开游戏太久了!干杯! – Ian 2013-03-24 18:58:14