[Solved] How to insert to a database with foreach? [closed]


You need to add the MySQL query inside the foreach() function, as well:

foreach ($qurum as $value) {
    $query2 = "INSERT INTO test (data_id, col2) VALUES ($id, $value)";
    mysqlExecute($query2);
}

Note that mysqlExecute() does not exist, you need to use your own function to execute the query.

Also note that executing SQL statements in a loop is not recommended because it slows down performance when executing multiple queries. If your web page does not have too much load or you’re just practicing it’s fine either way.

17

solved How to insert to a database with foreach? [closed]