PHP query with response from another query

0

I run a query that returns a list of IDs. With each ID of this list I want to make an insert into a second table.

My code:

<?php

$db = mysqli_connect("localhost","root","","test") or die("Erro ao conectar na base de dados MySQL!");
$query = "select id from country";
$result = mysqli_query($db, $query);

while ($row = mysqli_fetch_assoc($result)) {
    $var = $row["id"];
    mysqli_query($db, "insert into testando (numero) values ('$var')");

} 

mysqli_close($db);

?>

When I run, only 1 record is inserted into the database. If I run a second time, nothing happens. Where am I going wrong?

    
asked by anonymous 17.06.2018 / 06:36

0 answers