Jump to content

Submit Multiple Rows To MySQL Database


LHClaassen

Recommended Posts

Hi All,

 

I'm hoping someone can help me. I'm looking to create a form that will submit multiple entries to a MySQL database depending on the options selected on the form. I am able to submit single entries, but the multiple entire is a bit of a mystery to me.

 

I have attached an JPG image to show an example of how I would like the form to work.

 

I have also added the description/explination below to this example:

 

Example 1

The form was completed and three access types were selected. Thus Three entries, all with the Same Reference number were captured into the database

 

Example 2

The form was completed and Two Access Types were selected. Thus Two entries, all with the Same Reference number were captured into the database

Example 3

The form was completed and Four Access Types were selected. Thus Four entries, all with the Same Reference number were captured into the database

 

 

post-133805-13482403508064_thumb.jpg

Link to comment
Share on other sites

There a two easier ways that I can think of off the top of my head.

 

1, Concatenate the data required for the "Access Needed" field e.g:

$access = 'PC:Network:Parking';

Then to read you can split the data into an array with the explode function.

$access = explode(':', $access_data);

 

2, Add a seperate field in the database for each requirement and set it as ENUM(Yes/No)

 

Option 1 allows you to add as many different requirements as you want without amending the DB but could get messy or be inconsistent.

Option 2 would require you to add a new field for each new option but will be more structured.

 

That's my opinion at least.

Link to comment
Share on other sites

1. I've never used the explode function so will look how this works. If I understand it correctly, the explode function will add a new entry into the database for each access type (I might need more help here to ensure that I understand it correctly)?

 

2. On this option you are suggesting adding additional columns to the database for the fields? and then to just have them write to the different fields?

 

The main reason why I want to have multiple entries created is because I would like each person responsible for creating/actioning the required access types to clsoe the field once it has been created.

 

Hope I'm understanding your explination correctly?

Link to comment
Share on other sites

explode is a php function that splits a string into an array using a delimiter. you can set the delimiter as a character which is unlikely to appear in your data. In the example I gave I used the colon. explode takes a string and breaks it into chunks each time the delimiter is found. It doesn't do anything with the database. the point I was getting at, albeit rather indirectly, was you are duplicating work by adding a seperate record when the only thing changing is the access list.

 

2. On this option you are suggesting adding additional columns to the database for the fields? and then to just have them write to the different fields?

Basically yes. With option 2, which may be the better one based on your update, you could set the required colummn to 'no' once completed to remove it from the list. Or if you require an audit, rather than ENUM have it so you could set it so you can choose something like Required/Not Required/Completed, or 1/2/3 and use the code to define the status. You can then use one record have a cleaner DB and keep track of who has access to what.

 

To answer your original question though you could use a loop to add each entry to the DB for seperate records.

 

You are using a check box so you would need to create an array then loop through that to add the data into the DB.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.