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 に答える