alapimba Posted June 30, 2010 Share Posted June 30, 2010 Hi. I need to fo a form and the content be sent to a database but i'm stuck... I knwo hot to do forms and also how to send data to mysql using php. But now i need something a bit more complex and i'm stuck. I need to make a form lets say with "parent name, age, child name, child age" Some people has 1 child some people has 2 3 4...and i need to have it separated and not just write like "joe, bob, jack" in the same line. How can i do this? And how should the database be structured? i can't put "id, parent, age, c_name, c_age" because some ppl will need to have more than 1 child in the database. Don't know what to do Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted June 30, 2010 Share Posted June 30, 2010 I'd probably first create two tables. Lets call one "parent" and the other "child". The parent name and ID can be stored in the parent table while the children will be stored in the child table with a parent ID and of course their own unique id. That's a relational database for you... The javascript seems pretty straight forward. Not sure how you are doing it, but lets say you have 10 inputs for children name and age, just to make it simple, with the name input being "child_name" and age being "child_age". Assuming the user enters the data correctly, you can use PHP to loop through it because those inputs will be an array. For example, if you post the data, you can loop through $_POST['child_name']. I can't say for sure if several elements will be empty, but I'm pretty sure all 10 would be posted. So, a better way is to have them enter how many children they have and dynamically create those inputs, or just have an "Add Child" button. Hopefully this gets you on track. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.