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