inserting data into tables, linking and retrieving - help!
Moderator: General Moderators
inserting data into tables, linking and retrieving - help!
Sorry - I appear to be becoming a nuisance on this forum, buy hey I am a total newb!
I have quite a complex form (over 100 fields) which I have split over 4 pages.
I think it mmakes more sense to have each of those pages insert into a different table, but my question is, once on the second page, how can I link the data from the first table to the data on this table, in order to retrieve the correct data when select a row from all 4 tables?
Any ideas most appreciated.
I have quite a complex form (over 100 fields) which I have split over 4 pages.
I think it mmakes more sense to have each of those pages insert into a different table, but my question is, once on the second page, how can I link the data from the first table to the data on this table, in order to retrieve the correct data when select a row from all 4 tables?
Any ideas most appreciated.
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
My idea: Put the data already retreived in an array and then set them as hidden fields. Bit of coding:
This should print all the data you've put into that array as hidden fields, so they'll be send to the next page too! 
Don't forget to validate the data on the last page before using them in db (because they can be changed by editting HTML between pages).
And also use method='post' for such a big amount of data cause GET has some size limitations.
Alternatively you could probably use sessions for storing the data
Hope this helps
Code: Select all
<?php
$form_values = Array( // array with form values
"var1" => $_POST["var1"],
"var2" => $_POST["var2"],
"var3" => $_POST["var3"]
);
$output = ""; // buffer the output
forEach ($form_values as $var_name => $var_value) {
$output .= "<input type='hidden' name='$var_name' value='$var_value' />\r\n"; // add hidden field with data
// single quotes in the data should be also handled here, this is not complete code
}
echo $output; // print the buffer
?>Don't forget to validate the data on the last page before using them in db (because they can be changed by editting HTML between pages).
And also use method='post' for such a big amount of data cause GET has some size limitations.
Alternatively you could probably use sessions for storing the data
Hope this helps
in your first table create a unique Id when you first insert the date (auto-increment works well for this) then use that as a foriegn key in the rest of the tables.
table 1
uniqueId
name
address
table 2
table1UniqueId
email
phone
table 3
table1UniqueId
lastMovieWatched
lastBookRead
table 4
table1UniqueId
comment
otherStuff.
then all you have to pass is the uniqueId from page to page or store it in a session or what ever you want to do with it.
table 1
uniqueId
name
address
table 2
table1UniqueId
phone
table 3
table1UniqueId
lastMovieWatched
lastBookRead
table 4
table1UniqueId
comment
otherStuff.
then all you have to pass is the uniqueId from page to page or store it in a session or what ever you want to do with it.
Thanks Mark
Only problem with that is (should have said earlier). Because of the size of the form and the number pages, I decided to provide the user with a save and exit button, as well as save and continue, so they can retrieve and complete their application form at a later time.
This means I need to dump the data into a table before proceeding.
I just can't get my head around how to join the table from the first page with the table from the second, third and fourth pages.
Any other suggestions?
Only problem with that is (should have said earlier). Because of the size of the form and the number pages, I decided to provide the user with a save and exit button, as well as save and continue, so they can retrieve and complete their application form at a later time.
This means I need to dump the data into a table before proceeding.
I just can't get my head around how to join the table from the first page with the table from the second, third and fourth pages.
Any other suggestions?
How would define this variable $foreignkey though, in the code??
Would it be easier to do it with session variables, and if so, could someone show me how? I already have session_start() in my include file, so do I just add a $_SESSION['loan_id'] = (where do I get this value??)
Hope someone can ellaborate a bit further.
Would it be easier to do it with session variables, and if so, could someone show me how? I already have session_start() in my include file, so do I just add a $_SESSION['loan_id'] = (where do I get this value??)
Hope someone can ellaborate a bit further.