Simple(?) array of form input data needs to get into MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a problem (the core of it being that I am VERY new at PHP and
MySQL), wondering if anyone can suggest solutions.

I've been charged with handling creation of new web pages for entering
kids' data into a database for a local parents' club, for babysitting
co-ops and such.  What we want to do:

a) The registration form will ask for parents' name and contact info
(I'm not having any problem handling that), and ask them how many
children they have.

b) After submitting this, PHP puts these values into a MySQL database
(again, no problem) and will give them a second form, with one set of
form inputs for each child (I haven't figured out how to do this yet;
it sounds simple enough though). For example, if you said you have 3
kids, the next form might look like this:

Child #   First Name    Middle Name   Last Name  Gender  DoB     School Name

 1       _____________  ___________   _________   ____  _________ ___________
 2       _____________  ___________   _________   ____  _________ ___________
 3       _____________  ___________   _________   ____  _________ ___________

Where the fields will be named "Child1Number", "Child1FirstName", etc.,
all the way through "Child3SchoolName".

The PHP script that processes this form after it is submitted needs to
a) create a childID for each child (this is simply main
account-holder's ID with "c", "d", "e", etc., appended, and b) enter
the data for each child into the database, in the "child" table.

I have *THREE* PHP & MySQL books, and so far cannot figure out how to
do this in a sensible way, which I understand should be an array.  The
array chapters and examples all give sample code that is completely
useless for my purposes (generally the examples are of pre-determined
data, like tires and spark plugs and oil cans in an automotive catalog,
and how to print them out of the array into a web page).  Me, I'm
trying to take fresh input from the user, put it into an array somehow,
and have a loop (that I don't know how to write yet), generate a
"childID" for each child in turn, and enter each child's information in
turn into the database, keyed to that childID, and do so in an
efficient way.  (The inefficient way would be to, say, assume a maximum
of 15 children, and, not using an array, then have the script ask,
"Does child #1 exist in the form?  Yes?  Then create its user ID; now
enter its data in the database.  Does child #2 exist?...."  Hardly good
program design.  Even I know that, and I can't program my way out of
paper bag (I'm an HTML/CSS guy, not a programmer.  Yet.)  And, this
should be an associative array, not a numerically indexed one, since
other people who probably won't be programmers will need to be able to
look at this down the road and understand precisely what it does with
what data and why.

The other issue would be how to create the child form so that it only
has the number of fields required for the number of children they say
they have.  The whole for and each loop construction stuff is very,
very fuzzy in my head, in the absence of good examples.

PS: AFTER registration and login, if people want to be able to edit
this info, e.g. to add a new child in the family, there needs to be a
form that will load all of their existing family data and allow them to
edit it. No problem. But is there a way with PHP to have the "how many
children do you have" selector auto-reload the page with a new, empty
field for an additional child, if they had 3 kids but go to this
profile editing form and change it to say 4 kids?  I could do this with
Javascript, but if PHP itself can do it, that would be cool.  I suspect
that without JS, the best I can do is either a) always have a blank
child field just in case (but what if they just had twins?; not such a
great solution) or b) allow them to edit everything so far entered into
the DB, and if they change the number of kids have the form come back
after they submit it, with a new line of form fields for a new child
and a note at the top to add the new child's info.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux