I am trying to insert records in 2 different mysql tables. Here's the situation:
Table 1: is_main
that contains records of resorts with a primary key called id
.
Table 2: is_features
that contains a list of features that a resort can have (i.e. beach, ski, spa etc...). Each feature has got a primary key called id
.
Table 3: is_i2f
to connect each resort id with the feature id. This table has got 2 fields: id_i
and id_f
. Both fields are primary key.
I have created a form to insert a new resort, but I'm stuck here. I need a proper mysql query to insert a new resort in the is_main
table and insert in is_i2f
one record for each feature it has, with the id of the resort id id_i
and the id of the feature id id_f
.
$features = ['beach','relax','city_break','theme_park','ski','spa','views','fine_dining','golf'];
mysql_query("INSERT INTO is_main (inv_name, armchair, holiday, sipp, resort, price, rooms, inv_length, more_info)
VALUES ('$name', '$armchair', '$holiday', '$sipp', '$resort', '$price', '$rooms', '$length', '$more_info')");
$id = mysql_insert_id();
foreach($features as $feature) {
if(isset($_POST[$feature])) {
$$feature = 1;
mysql_query("INSERT INTO is_i2f (id_i, id_f) VALUES (" . $id . ", ?????????????? /missing part here????/ ); }
else {
$$feature = 0; }
}
Thanks. Please, I'm going CrAzY!!!!!!!!!!!!!!