I have 3 tables in MySQL :
country
language
country_language (it has the other 2 table's ids)
I want to insert the name
and description
into the country
table, the country id
and langid
to the country_language
table.
How can I do this?
It's working in the update section, but when I want to add a new country, it didn't insert the 2 ids into the country_language, just the name and the description.
php
$name = mysqli_real_escape_string($connect, $_POST["name"]);
$description = mysqli_real_escape_string($connect, $_POST["description"]);
$id=$_POST["country_id"];
if($id != '')
{
// Update query
$message = 'Data Updated';
}
else
{
mysqli_query($connect, "START TRANSACTION");
mysqli_query($connect, "INSERT INTO country(name, description) VALUES('$name', '$description')");
if(is_array($_POST["language"])) {
$values = Array();
foreach($_POST["language"] as $c2_id) $values[] = "($id, $c2_id)";
mysqli_query($connect, "INSERT INTO country_language(country_id, language_id) VALUES ".implode(",", $values));
}
mysqli_query($connect, "COMMIT");
$message = 'Data Inserted';
}