I have a MySQL db called table_music
Here I store artist, song,... this is something I will update from a form I have on a page.
Now I want to add genres to this form as well, so I made a table called song_genre
Here I have song_genre_id
, song_id
, genre_id
In my form I list the title of song from my table_music
Then I have fields where I can update the composer, length, year, and so on.
And there is also a checkbox list called genre from my song_genre
table with all the genres sorted alphabetically. I have these in a different table, since I might want to add genres later.
But I don't know how to insert these checked genres into my song_genre
table.
I've never used arrays before, so I'm lost here.
First I want to UPDATE
my table_music
and that is working fine.
Then I want to INSERT INTO
my new table (song_genre
) so I get the genre and the song_id
in here.
I think that's the right way to do it, so I am able to change the genre later or add or remove one genre if I need that as well one day.
I tried the following: but it doesn't seem to work:
foreach(echo $row_rs_genres['genre_id'] as $checked_value)
{
$query = "INSERT INTO song_genre (genre_id, song_id) VALUES ('$checked_value', $_POST['song_id'])";
$result = mysql_query($query) or die ("Unable to execute query: " . mysql_error());
}