Passing variables with VBcript
February 7, 2006 12:00 AM
Aaron, thanks for the tip. I got it working as far as passing the score variable, but once I add the ElapsedTime variable it chokes. Below are the working script, and the non-working script. Can you tell why the second would fail?Working<%@ Language=VBScript %> <% DIM score'Get the parameters posted from the lectora test titled "Final"' score=request.form("score")'Validate that this is actually from a Lectora test'if score="" THEN Response.Write "" Response.Write "Failure " Response.Write "" Response.Write "STATUS=500" Response.Write "
" Response.Write "Could not parse test results due to a parameter error." Response.Write ""else 'Write the results to an access database' ' First let us create Connection and Recordset objects' Set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.RecordSet") ' Open the connection to the ODBC source, in this case the Access database' Conn.Open "TestResults" ' Now, create the SQL statement' sSQL = "INSERT INTO MAIN(score) VALUES ( '" & score & "')" ' Execute the SQL statement, and set the recordset object' ' to the result of this execution. We obtain the resulting' ' records in Rs object' Set Rs = Conn.Execute(sSQL) ' Close the Recordset object and destroy it' Set Rs = Nothing ' You might want to release the resources for connection object, ' ' unless you want to use the same connection again in the later code' Conn.Close Set Conn = Nothing 'The response is optional, it is good for debugging' Response.Write "" Response.Write "Success " Response.Write "" Response.Write "STATUS=200" Response.Write "
" Response.Write(sSQL) Response.Write "
" Response.Write "Success." Response.Write ""end if%>Not working<%@ Language=VBScript %> <% DIM scoreDIM time'Get the parameters posted from the lectora test titled "Final"' score=request.form("score")time=request.form("ElapsedTime")'Validate that this is actually from a Lectora test'if score="" OR time="" THEN Response.Write "" Response.Write "Failure " Response.Write "" Response.Write "STATUS=500" Response.Write "
" Response.Write "Could not parse test results due to a parameter error." Response.Write ""else 'Write the results to an access database' ' First let us create Connection and Recordset objects' Set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.RecordSet") ' Open the connection to the ODBC source, in this case the Access database' Conn.Open "TestResults" ' Now, create the SQL statement' sSQL = "INSERT INTO MAIN(score,time) VALUES ('" & score & "', '" & time & "')" ' Execute the SQL statement, and set the recordset object' ' to the result of this execution. We obtain the resulting' ' records in Rs object' Set Rs = Conn.Execute(sSQL) ' Close the Recordset object and destroy it' Set Rs = Nothing ' You might want to release the resources for connection object, ' ' unless you want to use the same connection again in the later code' Conn.Close Set Conn = Nothing 'The response is optional, it is good for debugging' Response.Write "" Response.Write "Success " Response.Write "" Response.Write "STATUS=200" Response.Write "
" Response.Write(sSQL) Response.Write "
" Response.Write "Success." Response.Write ""end if%>Theonly difference is I'm trying to pass the ElapsedTime variable. Any ideas??Thanks for looking into this!
Discussions have been disabled for this post