Can i define a variable in the insert fucntion that will hav
Posted: Sat May 11, 2002 1:55 pm
This is my situation
I have created an online questionnaire, i am now at the stage where i will need to create the database.
Here is an example of the structure i have created:
questionnaire_users (table)
userid auto increment (primary key)
firstname
surname
email
passid
date
location
questionnaire_section_1
S1Q1
S1Q2_1
S1Q2_2
S1Q2_3
userid
questionniare_section_2
S2Q1
S2Q2
S2Q3
userid
and so on...
Two separate writes to the database will occur:
I only plan to make two separate connections to the database. All the information submitted will be passed from section to section of the questionnaire using hidden variables, thus when the user gets to the final section and submits them all the data collected from all the other forms will be wrote to the database. The second write will occur if the user selects they are a student on the finial section thus further questions will be asked, once they have answered these questions the second write to the database will occur.
The question i have is that because of the way i have designed this i will have to still put in varaible names in the insert statement that might not have values. Is it ok to have an insert like the following if for example slug has no value. If i cannot do this then i will have to do lots of If statements, saying if question 1 = "whatever" then write these variables else write these variables to the database, note also i will have lots of occurances of if question 1 = "whatever" then write these variables else write these variables to the database.
$query = "INSERT INTO news(slug, content, contact) VALUES('$slug', '$content', '$contact')";
What i am trying to ask is can i have one insert command for the whole questionnaire?
I have created an online questionnaire, i am now at the stage where i will need to create the database.
Here is an example of the structure i have created:
questionnaire_users (table)
userid auto increment (primary key)
firstname
surname
passid
date
location
questionnaire_section_1
S1Q1
S1Q2_1
S1Q2_2
S1Q2_3
userid
questionniare_section_2
S2Q1
S2Q2
S2Q3
userid
and so on...
Two separate writes to the database will occur:
I only plan to make two separate connections to the database. All the information submitted will be passed from section to section of the questionnaire using hidden variables, thus when the user gets to the final section and submits them all the data collected from all the other forms will be wrote to the database. The second write will occur if the user selects they are a student on the finial section thus further questions will be asked, once they have answered these questions the second write to the database will occur.
The question i have is that because of the way i have designed this i will have to still put in varaible names in the insert statement that might not have values. Is it ok to have an insert like the following if for example slug has no value. If i cannot do this then i will have to do lots of If statements, saying if question 1 = "whatever" then write these variables else write these variables to the database, note also i will have lots of occurances of if question 1 = "whatever" then write these variables else write these variables to the database.
$query = "INSERT INTO news(slug, content, contact) VALUES('$slug', '$content', '$contact')";
What i am trying to ask is can i have one insert command for the whole questionnaire?