2013-12-11 85 views
0

我正在用amazon API開發。這一切都有效,但是當我嘗試將服務器的響應保存到數據庫時,該過程不會出錯,但在數據庫中不會保存任何內容。Php我的sql插入不起作用

foreach ($offerList as $offer) { 
     $buyingPrice = $offer->getBuyingPrice(); 

     echo("LandedPrice\n"); 
     $landedPrice2 = $buyingPrice->getLandedPrice(); 
     echo("" . mysqli_query($con,'INSERT INTO `price` (mylanded) VALUES ("'. $landedPrice2->getAmount() .'")') . "\n"); 

     echo("ListingPrice\n"); 
     $listingPrice2 = $buyingPrice->getListingPrice(); 
     echo("" . mysqli_query($con,'INSERT INTO `price` (mylisting) VALUES ("'. $listingPrice2->getAmount() .'")') . "\n"); 
} 

頁面顯示18次LandedPrice ListingPrice然後循環成功。但DB保持爲空:(

+1

你能否提及你所面臨的錯誤。不工作是指? – Roopendra

+0

Did /你可以在某處設置「error_reporting(E_ALL)」嗎?任何有用的輸出? – MildlySerious

+0

「mysqli_query」的回聲是什麼?價格是一個整數還是浮點數?或者它是'串'? – Jurik

回答

0

mysqli_query()函數不應該返回NULL,前提是$link參數是正確的數據庫連接標識符。我認爲你的$con變量不能識別有效的連接。試試var_dump($con),你應該看到那裏的問題。

+0

yes,function did not see the連接在文件的開頭..我複製了,現在它工作..謝謝! –

0

確保連接成功 配合建立試試這個

$SQL= mysqli_query($con,'INSERT INTO prezzi (mylisting,mylanded,amlisting,amlanded) VALUES ("'. $listingPrice2->getAmount() .'",0,0,0)') ; 

你不需要爲了呼應這是一個INSERT查詢語句。 您可以檢查的成功和失敗。 。運行這個,因爲它是和檢查

if($SQL) { 
    echo 'insert-success'; 
} else { 
    echo 'insert-failure'; 
    } 
+0

請提及與現有查詢相比需要更正的OP。 – Roopendra

+0

LandedPrice插入失敗,var轉儲返回NULL。 這是表的查詢: $ SQL =「CREATE TABLE IF NOT EXISTS'price'( \t \t \t'id'詮釋NOT NULL AUTO_INCREMENT, \t \t \t PRIMARY KEY(ID), \t \t \t 'mylisting' DEC(6,2), \t \t \t'mylanded' DEC(6,2), \t \t \t'amlisting' DEC(6,2), \t \t \t'amlanded' DEC (6,2) )「; –

+0

這張表創建成功了嗎? – uvais