Using php/mysql.

I have a contacts table for a CRM software I made.

I want Companies to be able to create custom fields for their contacts.

The contacts table holds basic information like: ID, Name, Date_of_Birth, Address, and so on. The contacts table is filtered by Company_ID to find the company specific contacts.

There can be certain company related fields/groups that can be assigned to contacts for later filtering/reporting.

So to make this happen, here's what I'm thinking.

I created a 'groups' table with fields: ID, Name, Company_ID

I then created another table, groups_contacts, to join the group with the contact: ID, Group_ID, Contact_ID

I will make a page for companies to add/update/delete groups into the groups table.

When a new contact is added, right now I have a form users must fill out the basic contact info form. I then have the SQL to "INSERT INTO contacts...."

If my logic above is correct, I would then have to "INSERT INTO groups_contacts...."

But that's where I'm stuck. How do I get this to work?

I'd like to have check boxes next to all the company's custom group names. If any/all/some are checked then add them to the groups_contacts table.

Is that a good idea? I'd appreciate some help.