PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a form that has total of 16 boxes. 4 across. now on the first row of 4 its named plan1,min1,max1,percent1, row 2 its plan2,min2,max2,percent2 and so on
as you see i have all the names the same with numbers.
What I want to do is for each row I fll out have it insert into a table if i fill out the first 2 rows then it would insert 2 records. I am thinking its an aray thing but AM not sure.
Any help someone can give would be nice.
Thanks
Last edited by nite4000 on Wed Aug 31, 2011 12:04 pm, edited 1 time in total.
So this is a data entry form, and each row represents a record, and the user might enter anywhere from 1 to 4 records? I don't see any reason to use an array. You have 16 named input elements, some of which may be blank, right? So just use the first 4 to insert a record, check to see if the next row starts with a blank, and if so, you're done! If not, use the next 4 elements to insert another record, check to see if the next row starts with a blank, and if so, you're done. And so on.
You're right, I don't understand your question. If you were able to follow my directions and insert the new records in the table, then that constitutes the updating. You can always display the records in any manner that you please, independent of how or whether you have updated the table.
ok The last thing I am having trouble with is this.
i messed up last time
I have 16 boxes as before and 4 across and the first 4 is named plan1 next 4 is plan 2 and plan 3 and plan 4
Now I want to create a new record into the database for each one but the chkbox of the form next to the first box must me check and then boxes filled out and button pushed to create the new record.
I also want to remove the record if I was to unchk the box and push the button.
There's no need to have any checkboxes, that only complicates both the programming and the use of the form. In my first response, I tried to explain how you can do this. In your action script that receives the data, you will have 16 variables. Your PHP logic should test the first 4 to insure that they have been filled in, if they have, insert one record; then go to the next 4, check to see if they have been filled in, if they have, insert another record; then go to the next 4 ... get the idea?
This situation of having an uncertain number of data input elements is often handled in the first form with Javascript. Only one (or the minimum number, whatever that is) row of inputs would be displayed initially, plus a button that says "Add another record." The button would call a Javascript function to add a new line of <input> elements below the previous ones, assigning them names with suffixes just like you are doing now. Your action PHP script would test for the existence of the additional rows using isset(). This entails a little more Javascript, but can be designed to work very smoothly for the user.
on the add form have just 4 boxes then a button that says "Add New Plan" that then would add 4 new boxes and so on then saving would save them to database.
Then on the edit I could have same thing but show all the plans and have option to add more OR to remove them with chking a box. and saving would update the info.
What I need is to save the info. If i add 5 rows and then click save I need each one to save as a record. but not sure how to do it with it having [] on the textbox names i am getting array in the table.
Your PHP code looks like it should work, but I'm totally lost in your Javascript code. If you want to implement this approach (which I described as common, but I've never tried to write the code for it, myself), you'll have to work out how to add new rows to your HTML table. I'm not sure, at the moment, the best way to do that. I've often used the InnerHtml property of CSS elements, but that seems like it would be awkward in this situation. I would search Google for something like "javascript expanding table rows" or something.