Jump to content

Insert Multiple Records into Database Table


kallison

Recommended Posts

I have an HTML form that allows the user to enter education records. There are 3 fields in the form: Training_date, CourseID and StaffID. The course and employee are selected from a menu/list. On submit the record is stored in MySql tblrecords. This works fine to insert one record at a time. In a situation when several employees take the same course on the same day, I would like a form that requires the user to enter the date one time and select the course one time and then select multiple names from a multi-select list which will insert a single record in the table for each name selected. I hope I have explained this clearly enough. I am familiar with doing this using VBA in a MS Access environment but have not been able to get anything working with html and mysql. As well, my internet research has come up empty. BTW I am using Dreamweaver Cs5 as an html editor.I would be most appreciative if someone has the answer and can explain it to me in a way I can understand as I am very new to MySql and PhpMyAdmin.Thanking you in advance.

Link to comment
Share on other sites

However you have your form set up, just create one field for the date and the course, and then one field per user or however you select the users. I'm not sure if you need help setting up the form, or the PHP code, or the SQL query. If you're already processing one user, just set up the form like you want it to look, give each user field a different name, like "user1" through "user20", and get each value in PHP the same way you do now. You can go through the users and send one query for each user, or you can also send one query to insert all records. I'm not sure which of that you need help with.A common way to do this is to make a list of something like the users an array, and then loop through it in PHP. You do that by adding "[]" after the field name, e.g.:User 1: <input type="text" name="users[]">User 2: <input type="text" name="users[]">User 3: <input type="text" name="users[]">In PHP, you can loop through the users like this:

for ($i = 0; $i < count($_POST['users']); $i++){  echo 'User: ' . $_POST['users'][$i] . '<br>';}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...