[英]Inserting data into a database with an array
我不知道為什么查詢無法正常工作,可能是我錯過的一個小錯誤。 我嘗試根據是否匹配將數據插入到表列中。 我知道數據在我的數組中,但是我懷疑它正在寫的查詢給了我一個錯誤。
這是我的代碼:
$querytwo = 'INSERT INTO `' . $tablename . '` ' . ' (`' . $match_player_in_game . '`) ' . 'VALUES' . '(' . 'yes' . ')';
foreach ($player_fromsite as $match_player_in_game) {
for ($a = 0; $a < 11; $a++) {
if ($match_player_in_game == $home_players[$a]) {
// Insert a row of information into the table "example"
mysql_query($querytwo) or die(mysql_error());
} else {
}
}
}
消息返回'Undefined variable: match_player_in_game'
。
您需要將$querytwo
放入for()循環中,然后它將為您工作
它應該是
foreach($ player_fromsite as $ match_player_in_game){
$querytwo = 'INSERT INTO `' . $tablename . '` ' . ' (`' . $match_player_in_game . '`) ' . 'VALUES' . '(' . 'yes' . ')';
for ($a = 0; $a < 11; $a++) {
if ($match_player_in_game == $home_players[$a]) {
// Insert a row of information into the table "example"
mysql_query($querytwo) or die(mysql_error());
} else {
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.