2012-11-06 103 views
0

我想將信息輸入到數據庫中,並且遇到了一個問題,我確信我只是犯了一個簡單的錯誤。要更新我正在使用的表格:將數據從數組輸入到數據庫中

$conn->query("update webPrice set price= " . $amazonResult['price'] . " where asin = '" . $amazonResult['asin'] . "'"); 

$ conn是我的連接。價格始終輸入爲0.我知道那裏有信息,因爲當我執行print_r($ amazonResult)時,我看到了我想要插入到數據庫中的所有內容。代碼來獲得亞馬遜的信息是:

foreach($parsed_xml->GetMyPriceForASINResult as $item) { 
$asin2 =$item->attributes()->ASIN; 
$current = $item->Product; 

$status = $item->attributes()->status; 

     if (stristr($status, "Success") == true) 
{ 
     $amazonResult = array(
         'asin' => $asin2, 
      'price' => $current->Offers->Offer->BuyingPrice->ListingPrice,//AttributeSets->children('ns2', true)-> 
          ); 

我認爲這個問題是我的更新語句,但我的不知道它是什麼。 asin信息輸入正確。這些字段是price = double和asin = varchar。

編輯:這裏是print_r($ amazonResult)的結果;

Array ([asin] => SimpleXMLElement Object ([0] => 0176055452) [price] => SimpleXMLElement Object ([CurrencyCode] => USD [Amount] => 10.11)) 

回答

1

嘗試,加上引號'各地$amazonResult['price']

$conn->query("update webPrice set price= '" . $amazonResult['price'] . "' where asin = '" . $amazonResult['asin'] . "'"); 

編輯:按照您的編輯,因爲這些值是對象,

$conn->query("update webPrice set price= '" . $amazonResult['price']->Amount . "' where asin = '" . $amazonResult['asin']->0 . "'"); 
+0

謝謝我剛剛試過你的建議,並得到相同的結果。 – Jim

+0

編輯我的答案,根據問題中的編輯。看一看。 –

+0

我知道這會很簡單。謝謝,這很好。 – Jim

1

你必須把姓名的表格和兩個這種符號之間的字段:`並且您必須使用符號來表示值。 (就像coder1984說的)

$conn->query("update `webPrice` set `price` = '" . $amazonResult['price'] . "' where `asin` = '" . $amazonResult['asin'] . "'"); 
相關問題