Forum Moderators: open

Message Too Old, No Replies

Inserting data in multi-tables in one form(cold fusion)

cold fusion

         

nurminshah

2:17 pm on Jul 30, 2002 (gmt 0)



Hi...hope someone can help me. I need to create a form where data can be inserted into multi-tables in the database. So far I know how to insert data involving a single table...can anybody pleaseeeeee help me....thanks...

Min

mavherick

3:16 pm on Jul 30, 2002 (gmt 0)

10+ Year Member



hello nurminshah, welcome to Webmaster World.

We would need a little bit more info to help you out properly, but here's an example:

Example form:

<form action="test.cfm" method="post">
<input type="text" name="Field1" /><br />
<input type="text" name="Field2" /><br />
<input type="text" name="Field3" /><br />
<input type="text" name="Field4" /><br />
<input type="text" name="Field5" /><br />
<input type="submit" value="Send" />
</form>

Example test.cfm:

<cfquery name="insert1" datasource="mydb" dbtype="ODBC">
INSERT INTO table1
(id, col1, col2)
VALUES
(#Field1#, '#Field2#', '#Field3#')
</cfquery>

<cfquery name="insert2" datasource="mydb" dbtype="ODBC">
INSERT INTO table2
(id, col1, col2)
VALUES
(#Field1#, '#Field4#', '#Field5#')
</cfquery>

If you could provide us with more specific info like your form code and basic database schema, I'm sure we could help you out.

mavherick

nurminshah

4:35 pm on Jul 30, 2002 (gmt 0)



thanks for your reply, actually i'm developing an online test...so i need a form where the admin of the system can input new test questions. I have 4 tables...testtype(TT), testquestions(TQ), testchoices(TC) and testanswers(TA). With the fields below:

TT
TestTypeID
Type
Online (check Box)

Each type of test has many questions

TQ
TestQuestioID
Question
Type

Each question has many choices(options) A,B, C, D etc
TC
TestChoiceID
Choice_Letter
Choice_text
questionToChoice

TA
TestAnswerID
AnswerToChoice
Explaination

I wish to create a form where the admin of the online test can input all the data...OR my second alternative is to have multiple forms like the codes below

Code to input data into TestType table
<FORM ACTION="addtesttype2.cfm" METHOD="post">
Module Number : <input type="text" name="type" size="20"></p>
<p>Online? : <input type="checkbox" name="online" value="ON"></p>
<p>&nbsp;<input type="submit" value="Submit">
<input type="reset" value="Reset"></p>
</form>

addtesttype2.cfm

<CFINSERT DATASOURCE="mcaikni2" TABLENAME="table_testtype">

<HTML>
<HEAD>
<TITLE>Link Added</TITLE>
</HEAD>
<BODY>

link added
<FORM ACTION="addtestq2.cfm" Method="post">
<p>&nbsp;</p>
<p>Type of test <input type="text" name="type" size="20"></p>
<p>(Please input module number):</p>
<p>Question : <textarea rows="2" name="question" cols="46"></textarea></p>
<p><input type="submit" value="Submit">
<input type="reset" value="Reset"></p>
</FORM>

</BODY>
</HTML>

However, I feel that this is not good as the admin has to input by himself the type of test again ...<p>Type of test <input type="text" name="type" size="20"></p> where actually this is from the previous form....

sorry if it sounds complicated...many thanks, hope you can help.

Min

mavherick

4:59 pm on Jul 30, 2002 (gmt 0)

10+ Year Member



You can simply do something like this:

<cfoutput><input type="hidden" name="type" value="#form.type#" /></cfoutput>

instead of:

<p>Type of test <input type="text" name="type" size="20"></p>

that way you carry your type value over to your next script.

What you could also do is on the first page, add a text box with maybe the number of questions that there will be for this test and the max number of choices for a given question. that way you can simply generate the exact amount of boxes for your questions and setup everything in two pages. Let me know if your interested in an example.

mavherick

nurminshah

8:34 am on Jul 31, 2002 (gmt 0)



Oh,now then get it,i tried the value=#form.type# but i did not make the type as 'hidden'.I'll try this one. And can you please give me the example of what u suggested( using only 2 templates) for inserting new test questions. Thanks so much...:)

Min