Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用数组将数据插入数据库_Php_Mysql_Sql - Fatal编程技术网

Php 使用数组将数据插入数据库

Php 使用数组将数据插入数据库,php,mysql,sql,Php,Mysql,Sql,我不知道为什么查询不起作用,可能是我遗漏了一个小错误。我尝试将数据插入表列,这取决于它是否匹配。我知道数据在我的数组中,但我怀疑是我正在写的查询给了我一个错误 这是我的密码: $querytwo = 'INSERT INTO `' . $tablename . '` ' . ' (`' . $match_player_in_game . '`) ' . 'VALUES' . '(' . 'yes' . ')'; foreach ($player_fromsite as $match_playe

我不知道为什么查询不起作用,可能是我遗漏了一个小错误。我尝试将数据插入表列,这取决于它是否匹配。我知道数据在我的数组中,但我怀疑是我正在写的查询给了我一个错误

这是我的密码:

$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循环中,然后它将对您起作用

从站点将$player\u作为$match\u player\u加入游戏{

   $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 {

    }
}

}

在定义变量之前,您正在使用该变量。将查询放在循环内部,而不是外部。您需要将$querytwo放在for循环内部,然后它就可以为you@frosty11x你的评论应该是一个答案好吧,我现在明白了。我尝试在“字段列表”中仍然收到一条错误消息,说未知列“是”,在“字段列表”中仍然收到一条错误消息,说未知列“是”。你认为这是一个查询吗?这个查询在很大程度上看起来不错,但我会这样做:''“是的”;这可能会为您解决问题。请将此用于查询$querytwo=插入“$tablename”`$match\u player\u in_game`VALUES'yes';