Hi I have Problem in ASP.
I have created a Multi choice Question page in ASP with Submit button.
When I submit my page the User Selected values will be taken to the other page where validation will happen.
My problem is, the number of question will be dynamic and I need to validate the scores and give the final scores.
I tried to use a form collection via for each and validate with my answers but could nt successful
I have tried even writing my selected answers in data base but even that was also not successful .
Can any one know how to validate the answers with database dynamically?
If that’s not possible I want to write the form collections in to data base then validate.
I am attaching my code also. -
<!--#include file="Reload.asp"-->
-
-
-
-
<%
-
-
-
'WriteScore= Session("Score")
-
-
usname =Session("name")
-
dim chapid
-
chapid=11
-
-
Set conn = Server.CreateObject("ADODB.Connection")
-
-
'Connect to the database
-
strMDBpath = Server.MapPath("eLearning.mdb")
-
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
-
set rs = server.CreateObject ("ADODB.Recordset")
-
-
conn.Close
-
Set conn = Nothing
-
Set rs = Nothing
-
%>
-
-
-
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-
<html>
-
<head>
-
<title>Validate</title>
-
</head>
-
<body>
-
-
-
<%
-
-
-
NOTmyWishArray = array("xpage", "EPQ_Submit")
-
for each i in Request.form
-
isfound = false
-
for j = 0 to Ubound(NOTmyWishArray)
-
if lcase(NOTmyWishArray(j)) = lcase(i) then
-
isfound = true
-
exit for
-
end if
-
next
-
if isfound = false then
-
strBody = Request(i)
-
'response.write Request(i)
-
'response.write i
-
-
rs.Open "SELECT * FROM EvaluationTbl where UserName='"& Session("name") &"' AND ChapterID="&chapid&" AND QuestionID="&i&" "), conn, 1
-
If rs.recordcount = 0 then
-
strSql = "INSERT INTO EvaluationTbl (UserName, ChapterID, QuestionID, UserAnswer) VALUES ('"&Session("name")& "', '"&chapid& "', '"&i&"','"&Request(i)&"')"
-
conn.Execute(strSql)
-
-
rs.Close
-
conn.close
-
set rs=nothing
-
Set conn = nothing
-
-
-
else
-
conn.Execute("UPDATE EvaluationTbl SET UserAnswer ='" &Request(i)& "' WHERE ChapterID = " & chapid & " AND UserName = '" & Session("name") & "'AND QuestionID="&i&" ")
-
-
Response.Redirect("eLearning.asp")
-
close database
-
rs.Close
-
conn.close
-
set rs=nothing
-
Set conn = nothing
-
-
end if
-
-
end if
-
-
-
next
-
-
-
-
%>
-
-
-
-
-
-
</body>
-
</html>
Hello deepunarayan,
Sorry about that. Here is a new "Page2.asp" to use instead of the one above that should do everything you’re looking to do (I think). -
<%
-
NumberOfQuestionAsking = Request("xNumberOfQuestionAsking")
-
i = 1
-
Do Until (i = NumberOfQuestionAsking)
-
QuestionsAsked = QuestionsAsked & Request("xQuestion" & i & "KeyID") & ", "
-
i = (i + 1)
-
Loop
-
-
Set adoCon = Server.CreateObject("ADODB.Connection")
-
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")
-
Set rsAnswers = Server.CreateObject("ADODB.Recordset")
-
-
strSQL = "SELECT * FROM tblQuestion WHERE KeyID IN (" & QuestionsAsked & "0)"
-
rsAnswers.CursorType = 2
-
rsAnswers.LockType = 3
-
rsAnswers.Open strSQL, adoCon
-
-
i = 1
-
-
Function GetAnswer(QuestionKeyID, SubmittedAnswer)
-
rsAnswers.MoveFirst
-
Do Until (rsAnswers.EOF)
-
If (rsAnswers("KeyID").value = QuestionKeyID) Then
-
Response.Write(rsAnswers("Question").value & " ")
-
Response.Write("Answer:" & SubmittedAnswer & " ")
-
-
if (Trim(UCase(SubmittedAnswer)) = Trim(UCase(rsAnswers("Answer").value))) Then
-
Response.Write("<b>Correct</b><br />")
-
Else
-
Response.Write("<b>Incorrect</b><br />")
-
End If
-
Exit Function
-
End IF
-
i = (i + 1)
-
rsAnswers.MoveNext
-
Loop
-
End Function
-
%>
-
<html>
-
<head>
-
<title>Example Page 2</title>
-
</head>
-
<body>
-
<%
-
Do Until (i = NumberOfQuestionAsking)
-
GetAnswer(Request("xQuestion" & i & "KeyID"), Request("x" & i & "Answer"))
-
i = (i + 1)
-
Loop
-
%>
-
</body>
-
</html>
-
Hope this helps,
CroCrew~
13 2118
Hello deepunarayan,
Can you elaborate more on your 3rd paragraph? What do mean by “the number of question will be dynamic”?
Is it that you will have a database and within that database there is a table full of questions? So that when a person goes to the “Questions” page only a few random questions from that table are used.
Thnaks CroCrew,
ya actually till now i have not included that logic but in future it will be there. even the number of question will vary with the user. so the total submited values also vary.
if its fixed then i can easily hard code with the variable and write.. but i wanted to code for n number of question and verify the answers.
initially i coded for fixed number of question and the code was like this
<!--#include virtual="/adovbs.inc"-->
<!--#include file="connt.asp"-->
<!--#include file="Reload.asp"-->
<%
Set contEP = Server.CreateObject("ADODB.Connection")
contEP.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("eLearning.mdb")
SqlGet1="SELECT * FROM QuestionTbl where ChapterID=11 "
Set RecordsetEP =contEP.Execute(SqlGet1)
TheArray = RecordsetEP.Getrows
contEP.Close
Set contEP = Nothing
Set RecordsetEP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Verify Assessment Evaluatio Process</title>
</head>
<body body bgcolor="#dadfde" oncontextmenu="return false;">
<%
epQ1 = Request.Form("1")
epQ2 = Request.Form("2")
epQ3 = Request.Form("3")
epQ4 = Request.Form("4")
epQ5 = Request.Form("5")
%>
<%
function Score ()
Score=0
if (epQ1 = TheArray(7,0) ) Then
Score = Score+1
end if
if (epQ2 = TheArray(7,1) ) Then
Score = Score+1
end if
if (epQ3 = TheArray(7,2)) Then
Score = Score+1
end if
if (epQ4 = TheArray(7,3) ) Then
Score = Score+1
end if
if (epQ5 = TheArray(7,4) ) Then
Score = Score+1
end if
Session.Contents.Remove("Score")
Session("Score") = Score
end function
%>
<%
DIM mySQL, objRS
mySQL = "SELECT Count(*) AS intTotal FROM QuestionTbl"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
' Display result
Response.Write ("Youre Score is "& Score & "out of ")
Response.Write objRS("intTotal")
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
<hr>
<form action="EvaluationDbWirteEP.asp" name="Content1" method="post" target="contentFrame">
<input type="submit" name="Submit_Scores" value="Submit Your Score"/> <input type="reset" name="Reset" />
</form>
</body>
</html>
now i wanted for n number of question as its difficult hard code when questions increase or decrease
Check back later today I will have something posted for you.
CroCrew~
it will be really helpful for me.. thanks a lot
Hello deepunarayan,
Sorry for not getting back to you sooner but, I have an emergency. Below is a start to your solution. I can see that you’re using Microsoft Access as your database so I will try to use that in the solution.
First the database needs a table called “tblQuestion” and within that table there needs to be three fields. First field is called “KeyID” and that needs to have a data type of “AutoNumber”. The tow other fields are called “Question” and “Answer” and they need a data type of “Text”. After creating the table in your database; create about ten records for you testing.
Now create the two files/pages (Page1.asp and Page2.asp) below and give it a try. This should give you a start.
Page1.asp: -
<%
-
NumberOfQuestionAsking = 5
-
-
Set adoCon = Server.CreateObject("ADODB.Connection")
-
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")
-
Set rsQuestions = Server.CreateObject("ADODB.Recordset")
-
-
strSQL = "SELECT TOP " & NumberOfQuestionAsking & " KeyID, Question FROM tblQuestion ORDER BY rnd(KeyId)"
-
rsQuestions.CursorType = 2
-
rsQuestions.LockType = 3
-
rsQuestions.Open strSQL, adoCon
-
-
i = 1
-
%>
-
<html>
-
<head>
-
<title>Example Page 1</title>
-
</head>
-
<body>
-
<form name="xForm" action="Page2.asp" method="post">
-
<input type="hidden" name="xNumberOfQuestionAsking" value="<%Response.Write(NumberOfQuestionAsking)%>">
-
<%Do Until (rsQuestions.EOF)%>
-
<input type="hidden" name="xQuestion<%=i%>KeyID" value="<%Response.Write(rsQuestions("KeyID").value)%>">
-
<%Response.Write(rsQuestions("Question").value)%> Answer:<input type="text" name="x<%=i%>Answer"><br />
-
<%i = (i + 1)%>
-
<%rsQuestions.MoveNext%>
-
<%Loop%>
-
-
<input type="submit" value="Submit" name="xSubmit">
-
</form>
-
</body>
-
</html>
-
Page2.asp -
<%
-
NumberOfQuestionAsking = Request("xNumberOfQuestionAsking")
-
i = 1
-
Do Until (i = NumberOfQuestionAsking)
-
QuestionsAsked = QuestionsAsked & Request("xQuestion" & i & "KeyID") & ", "
-
i = (i + 1)
-
Loop
-
-
Set adoCon = Server.CreateObject("ADODB.Connection")
-
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")
-
Set rsAnswers = Server.CreateObject("ADODB.Recordset")
-
-
strSQL = "SELECT * FROM tblQuestion WHERE KeyID IN (" & QuestionsAsked & "0)"
-
rsAnswers.CursorType = 2
-
rsAnswers.LockType = 3
-
rsAnswers.Open strSQL, adoCon
-
-
i = 1
-
%>
-
<html>
-
<head>
-
<title>Example Page 2</title>
-
</head>
-
<body>
-
<%
-
Do Until (rsAnswers.EOF)
-
Response.Write(rsAnswers("Question").value & " ")
-
Response.Write("Answer:" & Request("x" & i & "Answer") & " ")
-
-
if (Trim(UCase(Request("x" & i & "Answer"))) = Trim(UCase(rsAnswers("Answer").value))) Then
-
Response.Write("<b>Correct</b><br />")
-
Else
-
Response.Write("<b>Incorrect</b><br />")
-
End If
-
i = (i + 1)
-
rsAnswers.MoveNext
-
Loop
-
%>
-
</body>
-
</html>
-
I have not tested this out yet so please let me know if something is not working and I will be happy to help out more.
Hope this helps,
CroCrew~
hay CroCrew, i am really thanksful for your kind reply.. thanks for u r time.
Page1.asp there is no problem. once i submit the form in Page2.asp it is going to a an infinite loop.
i tried to rectify this but failed. in Screen i am able to see few data being to posted. please help in clearing this bug so once i am able view u r output in Page2.asp then it will help me a lot in understanding.
the error is
Error Type:
Active Server Pages, ASP 0113 (0x80004005)
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
/Page2.asp
Sorry,
Change line 4 in "Page2.asp
From: - Do Until (i = NumberOfQuestionAsking)
To: - Do Until (i => NumberOfQuestionAsking)
i have changed code to
Do Until (i >= NumberOfQuestionAsking)
but still it is in Infinite loop..
the error reads the same
Please try the following:
* Click the Refresh button, or try again later.
* Open the localhost home page, and then look for links to the information you want.
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services
Technical Information (for support personnel)
* Error Type:
Active Server Pages, ASP 0113 (0x80004005)
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
/Page2.asp
* Browser Type:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
* Page:
POST 180 bytes to /Page2.asp
* POST Data:
xNumberOfQuestionAsking=5&xQuestion1KeyID=7&x1Answ er=&xQuestion2KeyID=4&x2Answer=&xQuestion3KeyID=5& x3Answer=&xQuestion4KeyID=2&x4Answer=&xQuestion5Ke yID=3&x5Answer=&xSubmit=Submit
* Time:
Monday, October 12, 2009, 5:48:42 PM
* More information:
Microsoft Support
Insert this after line 8 and before line 9: -
Response.Write(QuestionsAsked)
-
Response.End
-
Then tell me what you get when you run it.
ok, found the problem.
Change line 4 in "Page2.asp
From: - Do Until (i => NumberOfQuestionAsking)
To: - Do Until (i => int(NumberOfQuestionAsking))
Don't do the: -
Response.Write(QuestionsAsked)
-
Response.End
-
Thanks a lot CroCrew,
Your solution really worked. I thank you for your time and patience.
The solution was very perfect. The only thing I changed is that in Page1.asp as you are selecting the top 5 question in random order and in page2.asp you just select answers with order by “KeyID” and compare with form collection so the result will be incorrect for many right answers.
Now am just using all the questions in DB to display in order so I just selected all (select *) question in Page one and compared there answers in page2.asp with question order itself. But I have to implement the random order. If you have any idea then please share with me. I have one logic that, if we submit the answers as an hidden field in the page1.asp with same KeyID and compare in page2.asp will it work out. I am trying on this.
Sorry for the late reply. I once again thank you for your kind help.
Hello deepunarayan,
Sorry about that. Here is a new "Page2.asp" to use instead of the one above that should do everything you’re looking to do (I think). -
<%
-
NumberOfQuestionAsking = Request("xNumberOfQuestionAsking")
-
i = 1
-
Do Until (i = NumberOfQuestionAsking)
-
QuestionsAsked = QuestionsAsked & Request("xQuestion" & i & "KeyID") & ", "
-
i = (i + 1)
-
Loop
-
-
Set adoCon = Server.CreateObject("ADODB.Connection")
-
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")
-
Set rsAnswers = Server.CreateObject("ADODB.Recordset")
-
-
strSQL = "SELECT * FROM tblQuestion WHERE KeyID IN (" & QuestionsAsked & "0)"
-
rsAnswers.CursorType = 2
-
rsAnswers.LockType = 3
-
rsAnswers.Open strSQL, adoCon
-
-
i = 1
-
-
Function GetAnswer(QuestionKeyID, SubmittedAnswer)
-
rsAnswers.MoveFirst
-
Do Until (rsAnswers.EOF)
-
If (rsAnswers("KeyID").value = QuestionKeyID) Then
-
Response.Write(rsAnswers("Question").value & " ")
-
Response.Write("Answer:" & SubmittedAnswer & " ")
-
-
if (Trim(UCase(SubmittedAnswer)) = Trim(UCase(rsAnswers("Answer").value))) Then
-
Response.Write("<b>Correct</b><br />")
-
Else
-
Response.Write("<b>Incorrect</b><br />")
-
End If
-
Exit Function
-
End IF
-
i = (i + 1)
-
rsAnswers.MoveNext
-
Loop
-
End Function
-
%>
-
<html>
-
<head>
-
<title>Example Page 2</title>
-
</head>
-
<body>
-
<%
-
Do Until (i = NumberOfQuestionAsking)
-
GetAnswer(Request("xQuestion" & i & "KeyID"), Request("x" & i & "Answer"))
-
i = (i + 1)
-
Loop
-
%>
-
</body>
-
</html>
-
Hope this helps,
CroCrew~
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PHPkemon |
last post by:
Hi there,
A few weeks ago I made a post and got an answer which seemed very logical.
Here's part of the post:
PHPkemon wrote:
> I think I've figured out how to do the main things like...
|
by: Robert V |
last post by:
Hi all, I could use some help programming on of my Perl script to handle
different submit buttons within the same form. Here is what I have so far.
A user goes to a Web form and inputs some data...
|
by: Code4u |
last post by:
I need to design data storage classes and operators for an image
processing system that must support a range of basic data types of
different lengths i.e. float, int, char, double. I have a...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: xenophon |
last post by:
I have a grid with checkboxes in it. When a checkbox is un/checked, I
want to set a true-false value in an array. Then on PostBack I can
work with that array.
I know I need to use...
|
by: c#2006user |
last post by:
Hi everyone.
i know there is a lot of code and ive reduced it as much as i could,
its a bit much to ask but i am really stuck!
i've been at this for a week! this is converted from vb to c# and...
|
by: Ming Yeung |
last post by:
I was wondering if .NET had the equivalent of Frames, Global Objects, and
most importantly DataModules like in Delphi?
|
by: Brad Isaacs |
last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database.
I am using Visual Studio 2005 and developing on my Local machine. I am
working with Login controls ASP.Configuration, I...
|
by: souporpower |
last post by:
Hello All
I am trying to activate a link using Jquery. Here is my code;
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"</script>
<script...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |