Page 1 of 1

How do I parse my complicated html form?

Posted: Fri Jun 14, 2002 2:05 pm
by Matt Phelps
I'm pretty new to PHP but after struggling along with phpNuke for my website for a while (and hating it immensely) I have decided to write the code for my own site from scratch. So far I have made some good progress but one of the problems I'm trying to solve is as follows:

I need to have a html form with several rows of information and I want to enter each row of information into a mySQL table individually. So there will be 19 rows of text boxes/dropdown menus on one form and each row will have it's own entry in the database.

The form is actually a race results entry form and each driver will have their own row of data (where they finished, their race number, number of laps completed) etc but all the entries will be for the same race and are therefore on the same form.

How do I process the form so that it creates several database entries rather than just one row?

Any help would greatly appreciated!

Posted: Fri Jun 14, 2002 2:33 pm
by toppac
I am doing something similar and here is my approach. If you name each entry field with a name and number, IE racer1, you can parse that quite easily. Just add some code like follows

Code: Select all

$counter = 1;
$racer = 'racer'.$counter;
This gives you a variable 'racer1'. Now just loop thru the $_POST[] variables and update the counter.

Code: Select all

$counter++;
$racer = 'racer'.$counter;
As your looping, just refernece the $racer variable, and it will give you the correct one.

I know this may not be the best way to do it, but it works. I am fairly new to php, so you may want to wait for some more advice

Posted: Fri Jun 14, 2002 2:35 pm
by jason
You would probably have to loop through the results you recieve from the form, and for each "row" of your form, do an insert into the database.