Пытаюсь записать значение ключей массива в таблицу mysql, но вылазеет ошибка (см. ниже), вот сам код
foreach ($array_id as $id) {
$all_company = array(
'id' => $id['id'],
'name' => $id['country']
);
$sql = "INSERT INTO api-company (id, country) VALUES ({$all_company['id']}, {$all_company['name']})";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
INSERT INTO api-company (id, country) VALUES (5414, Croatia)
Error: INSERT INTO api_company (id, country) VALUES (5414, Croatia)
Unknown column 'Croatia' in 'field list'Error: INSERT INTO api_company (id, country) VALUES (5403, )
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1Error: INSERT INTO api_company (id, country) VALUES (5397, Turkey)
Unknown column 'Turkey' in 'field list'Error: INSERT INTO api_company (id, country) VALUES (5393, Greece)
Unknown column 'Greece' in 'field list'Error: INSERT INTO api_company (id, country) VALUES (5380, Turkey)
Что я не так делаю? Проверил вроде должно работать, помогите плиз