0
當我向mysql輸入數據時,如下所示,我想將所有數據都放在一行中。但由於我使用數組輸入數據,我只能同時訪問兩個元素。那麼,我怎樣才能將數據輸入到一行?下面是我的代碼剪斷如何在php中使用數組輸入數據到mysql數據庫?
$array = array("AAPL","GOOG","YHOO","FB","MSFT","NKE","SBUX");
foreach ($array as $s) {
$sql = "INSERT INTO portfolio ({$s} , {$sss}) VALUES ('{$amount}', '{$value}')";
}
提供您的表架構和代碼,用於插入數據和代碼,您嘗試從db獲取數據 – Alex
[Little Bobby](http://bobby-tables.com/)說[您的腳本處於SQL風險中注入攻擊。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –