I currently have a dropdown box which enters an integer into a table. It’s adding $myVariable choice to a list in the database based on the ID singularly.
What i’m struggling to do is convert this dropdown selection system to a checkbox system where the user checks which $myVariable’s and inserts them into a database.
How can I insert multiple ID’s [myVariableID] into a database in one insert statement?
Edit:
I have a table with a list of X. The X has an ID, so I want to insert that ID into another table.
X 1 has ID 1
X 2 has ID 2
Inserting these values into a table allows me to see what X have been associated using a linking table.
Therefore, with a list of checkboxes (Outputs all of X that has been added), I need to insert the ID of X multiple times into the linking table.
It is currently limited because the dropdown selects X, and X ID. If I use checkboxes, how do I dynamically grab the ID of X, and insert whatever X‘s are selected, and add X ID multiple based on the checkbox selections.
Example
Name ID
X1 || 1
X2 || 2
X3 || 3
X4 || 4
User selects X1, X2, insert ID 1, 2 into a database table. I can’t have $var1, $var2, .. etc because the list might be added to. This is why I thought of an array or foreach
Problem:
A dropdown selection has one value ($variable)
A checkbox system (What I want) has multiple possible values.
INSERTsupports inserting multiple values.Quick example: