Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: problem collecting form data into database (quiz)


Message #1 by craigmrobertson@h... on Fri, 21 Sep 2001 16:12:31
i have a page which displays a list of questions filtered by a category id 

from a questions table. a user id is captured from a previous login screen 

and stored in a session variable. the questions are listed in a form. the 

form captures user's answers and sends the user id, category id, question 

id and the answer to a results table. it works somewhat, and i don't get 

an error, but only the user id and category id get sent to the results 

table. the question id and answer never show up. can anyone help? deadline 

are looming and i'm soon to be found out to be a charlatan! cheers,



Moose



here is the code :



<%@ Language=VBScript %>

<% option explicit %>

<% 

dim strConnection

dim adoDataConn

dim SQLStmt

dim q



'########the connection works fine###########

strConnection = "driver

{mysql};server=10.0.0.246;uid=root;database=skillsline"

Set adoDataConn = Server.CreateObject("ADODB.Connection") 

adoDataConn.Open strConnection 



if NOT isempty(Request.Form("Insert")) then

adoDataConn.Execute "insert into tna_results (user_id, category_id, q_id, 

a) " _

	& "values (" _

	& "'" & Request.Form("user_id") & "', " _

	& "'" & Request.Form("category_id") & "', " _

	& "'" & Request.Form("q_id") & "', " _

	& "'" & Request.Form("a") & "')"

	response.redirect "./tna_categories.asp"

end if



SQLStmt = "select * from tna_questions where category_id = "_

	& request.querystring("category_id")



set q = Server.CreateObject("ADODB.Recordset")

q.ActiveConnection = strConnection

q.Open SQLStmt, , , 4, 1

	      

%>



'##############here is the form bit############

<FORM action="tna_questions.asp"  METHOD=POST>

<input type="hidden" name="user_id" value=<% response.write session

("user_id") %>>

<input type="hidden" name="category_id" value=<% response.write q

("category_id") %>>

<% do until q.eof %>

	<p>

	<% response.write q("q_text") %><p>

	1<input type="radio" name=<% response.write q("q_id") %> value=1>

	2<input type="radio" name=<% response.write q("q_id") %> value=2>

	3<input type="radio" name=<% response.write q("q_id") %> value=3>

	4<input type="radio" name=<% response.write q("q_id") %> value=4>

	5<input type="radio" name=<% response.write q("q_id") %> value=5>

<p>

<% q.movenext 

loop 

q.close

set q=nothing%>

</form>

Message #2 by David Cameron <dcameron@i...> on Mon, 24 Sep 2001 09:24:53 +1000
I'm not sure what your error is.



Right click on the page and check the HTML that is generated. That should

point you to your error.



regards

David Cameron

nOw.b2b

dcameron@i...



-----Original Message-----

From: craigmrobertson@h... [mailto:craigmrobertson@h...]

Sent: Saturday, 22 September 2001 2:13 AM

To: ASP Databases

Subject: [asp_databases] problem collecting form data into database

(quiz)





i have a page which displays a list of questions filtered by a category id 

from a questions table. a user id is captured from a previous login screen 

and stored in a session variable. the questions are listed in a form. the 

form captures user's answers and sends the user id, category id, question 

id and the answer to a results table. it works somewhat, and i don't get 

an error, but only the user id and category id get sent to the results 

table. the question id and answer never show up. can anyone help? deadline 

are looming and i'm soon to be found out to be a charlatan! cheers,



Moose



here is the code :



<%@ Language=VBScript %>

<% option explicit %>

<% 

dim strConnection

dim adoDataConn

dim SQLStmt

dim q



'########the connection works fine###########

strConnection = "driver

{mysql};server=10.0.0.246;uid=root;database=skillsline"

Set adoDataConn = Server.CreateObject("ADODB.Connection") 

adoDataConn.Open strConnection 



if NOT isempty(Request.Form("Insert")) then

adoDataConn.Execute "insert into tna_results (user_id, category_id, q_id, 

a) " _

	& "values (" _

	& "'" & Request.Form("user_id") & "', " _

	& "'" & Request.Form("category_id") & "', " _

	& "'" & Request.Form("q_id") & "', " _

	& "'" & Request.Form("a") & "')"

	response.redirect "./tna_categories.asp"

end if



SQLStmt = "select * from tna_questions where category_id = "_

	& request.querystring("category_id")



set q = Server.CreateObject("ADODB.Recordset")

q.ActiveConnection = strConnection

q.Open SQLStmt, , , 4, 1

	      

%>



'##############here is the form bit############

<FORM action="tna_questions.asp"  METHOD=POST>

<input type="hidden" name="user_id" value=<% response.write session

("user_id") %>>

<input type="hidden" name="category_id" value=<% response.write q

("category_id") %>>

<% do until q.eof %>

	<p>

	<% response.write q("q_text") %><p>

	1<input type="radio" name=<% response.write q("q_id") %> value=1>

	2<input type="radio" name=<% response.write q("q_id") %> value=2>

	3<input type="radio" name=<% response.write q("q_id") %> value=3>

	4<input type="radio" name=<% response.write q("q_id") %> value=4>

	5<input type="radio" name=<% response.write q("q_id") %> value=5>

<p>

<% q.movenext 

loop 

q.close

set q=nothing%>

</form>

  Return to Index