URGENT HELP NEEDED WITH DATABASES
-
hi helpers, me currently doing my course final year project in sch and i met some probelm with databases. I have to develope an online quiz setter. What this project does is i wrote a html which will run the program from web browser throught the server and it will pull out the question from my xml file to display it. So after completing the quiz..it will store the question number and the score for the particular quiz into the database. But unfortunatly it wont store anything into the database. Below are all my code from different file..it will link from pages to pages. I not surea about where goes wrong. Pls Help :(
-
HTML File
<html>
<script>
var strNextQ
var objXmlHTTP,objXmlDOM;
var aQuest; //to store question ids
var aAnswer = new Array(); // to track the result
var aSelected = new Array(); // to store user's response
var count = 0; //to store the current question no
var ansSel = 0; //to store user's selection
var QuizDuration = 25 * 60 ; // 25 minutes
var timerID; //to store the setInterval fun's id
var radIndex = -1; //to store the selected radio's indexfunction loadImage(imgNum){
document.images[0].src = my_images[imgNum]
}//constructor like function
//here XML objects are created and
//No of questions as well as question ids list
//are fetched from the server.function init(){
objXmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
objXmlDOM = new ActiveXObject("Microsoft.XMLDOM");
objXmlHTTP.open("POST","Level3.asp?Action=Start",false);
objXmlHTTP.send("");
temp =objXmlHTTP.ResponseText;
aQuest = temp.split(",");//initialize the user's answers list
for(i=0;i<aQuest.length; i++){
aAnswer[i] = 0; // 0 for wrong; 1 for right answer
aSelected[i] = -1; // to store the radio's index
}if(count < aQuest.length) {
url = "Level3.asp?Action=NextQ&QNo=" + aQuest[count];
objXmlHTTP.open("POST", url ,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);//parse the response content fetched from the server
//and display the question
parseQ();
}//change the Start button's caption and its click event
document.frm.btnFinish.value = "End Quiz";
document.frm.btnFinish.onclick = showResult; //function
//start the timer
timerID = setInterval("timer()",1000);
}function getPreQ() {
//update the user's answers list
checkAnswer();//decrement the question no - i.e. to previous Question
count--;//stop the timer
clearInterval(timerID);//fetch the question for the aQuest[count] id
url = "Level3.asp?Action=NextQ&QNo=" + aQuest[count];
objXmlHTTP.open("POST",url ,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);//parse the response content fetched from the server
//and display the question
parseQ();//start the timer
timerID = setInterval("timer()",1000);
}function getNextQ() {
//update the user's answers list
checkAnswer();//increment the question no - i.e. to next Question
count++;//stop the timer
clearInterval(timerID);url = "Level3.asp?Action=NextQ&QNo=" + aQuest[count];
objXmlHTTP.open("POST", url ,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);
//parse the response content fetched from the server
//and display the question
parseQ();//start the timer
timerID = setInterval("timer()",1000);
}
function parseQ(){
//fetch the question from the XML Object
//format the displaystrOut = "<table border=0 align=center width=80%>";
strOut += "<tr><td colspan=2><b>";
strOut += "Question No: " + (count+1) + " of ";
strOut += aQuest.length + "</b></td></tr>";
strOut += "<tr><td colspan=2> </td></tr>";temp = objXmlDOM.selectSingleNode("data/qtext");
strOut += "<tr><td colspan=2><b>"+temp+"</b></td></tr>";
strOut += "<tr><td colspan=2> </td></tr>";Nodes = objXmlDOM.selectNodes("data/choice");
for(i=0;i<Nodes.length;i++){
strOut += "<tr><td align=center width=10%>";
strOut += "<input type=radio name=ansUsr ";
strOut += " onClick='ansSel=" + (i+1);
strOut += ";radIndex=" + i + "' ";
strOut += "value=" + (i+1) + "></td><td>";
strOut += Nodes.item(i).text + "</td></tr>";
}//set ansNo (hidden field) to the actual answer
temp = objXmlDOM.selectSingleNode("data/answer");
document.frm.ansNo.value = temp;strOut += "<tr><td colspan=2> </td></tr>";
strOut += "<tr><td colspan=2>";if(count != 0 ){
strOut += "<input type=button value=Back ";
strOut += " onClick='getPreQ()'> ";
}if(count < aQuest.length-1){
strOut += " <input type=button value=Submit ";
strOut += " onClick='getNextQ()'>";
}strOut += "</td></tr></table>";
//set the strOut content to <P> tag named QArea
QArea.innerHTML = strOut;//set the default value to ansSel
ansSel = 0;
radIndex = -1;//check the radio if user has selected previously
if (aSelected[count] != -1) {
radIndex = aSelected[count];
ansSel = radIndex + 1;
document.frm.ansUsr[radIndex].checked = true;
}
}function checkAnswer(){
//store the selected radio's index
aSelected[count] = radIndex;//if the user selection matches the actual answer
if (ansSel == document.frm.ansNo.value)
aAnswer[count] = 1;
else
aAnswer[count] = 0;
}function showResult() {
rights = 0;//stop the timer
clearInterval(timerID);//update the user's answers list
checkAnswer();//count no of answers
for(i=0;i<aAnswer.length;i++){
if(aAnswer[i] == 1)
rights++;
}
strRes = "<h2 align=center><br>";//if all the answers are correct then greet
if(rights == aAnswer.length)
strRes += "<br><br>Congratulations, you have answered all the questions correctly !!";strRes += "Online Quiz 3<br>"
strRes += "<br><br>Your score is " + rights;
strRes += " out of " + aAnswer.length;if(aAnswer.length/2 <= rights)
strRes += "<br><font color=#0033FF>Passed</font><br><br>";else
strRes += "<br><font color=#FF0000>Failed</font><br><br>";"</h2>";
document.write(strRes); //Show result
strRes = "<h3 align=left>";
strNextQ = "";
if(aAnswer[0] == 1)
strRes += "<br>Question 1: Correct<br>"; //compair the answer and display strRes
else {
strRes += "<br>Question 1: Wrong<br>";
strNextQ += "1,"; //record down to wrong ID
}
if(aAnswer[1] == 1)
strRes += "<br>Question 2: Correct<br>";
else{
strRes += "<br>Question 2: Wrong<br>";
strNextQ += "2,";
}
if(aAnswer[2] == 1)
strRes += "<br>Question 3: Correct<br>";
else {
strRes += "<br>Question 3: Wrong<br>";
strNextQ += "3,";
}
if(aAnswer[3] == 1)
strRes += "<br>Question 4: Correct<br>";
else {
strRes += "<br>Question 4: Wrong<br>";
strNextQ += "4,";
}
if(aAnswer[4] == 1)
strRes += "<br>Question 5: Correct<br>";
else{
strRes += "<br>Question 5: Wrong<br>";
strNextQ += "5,";
}if(aAnswer[5] == 1)
strRes += "<br>Question 6: Correct<br>";
else{
strRes += "<br>Question 6: Wrong<br>";
strNextQ += "6";
}
if(aAnswer== 1)
strRes += "<br>Question 7: Correct<br>";
else{
strRes += "<br>Question 7: Wrong<br>";
strNextQ += "7";
}
if(aAnswer[7] == 1)
strRes += "<br>Question 8: Correct<br>";
else{
strRes += "<br>Question 8: Wrong<br>";
strNextQ += "8";
}
if(aAnswer== 1)
strRes += "<br>Question 9: Correct<br>";
else{
strRes += "<br>Question 9: Wrong<br>";
strNextQ += "9";
}
if(aAnswer[9] == 1)
strRes += "<br>Question 10: Correct<br>";
else{
strRes += "<br>Question 10: Wrong<br>";
strNextQ += "10";
}
if(aAnswer[10] == 1)
strRes += "<br>Question 11: Correct<br>";
else{
strRes += "<br>Question 11: Wrong<br>";
strNextQ += "11";
}
if(aAnswer[11] == 1)
strRes += "<br>Question 12: Correct<br>";
else{
strRes += "<br>Question 12: Wrong<br>";
strNextQ += "12";
}
if(aAnswer[12] == 1)
strRes += "<br>Question 13: Correct<br>";
else{
strRes += "<br>Question 13: Wrong<br>";
strNextQ += "13";
}
if(aAnswer[13] == 1)
strRes += "<br>Question 14: Correct<br>";
else{
strRes += "<br>Question 14: Wrong<br>";
strNextQ += "14";
}
if(aAnswer[14] == 1)
strRes += "<br>Question 15: Correct<br>";
else{
strRes += "<br>Question 15: Wrong<br>";
strNextQ += "15";
}
if(aAnswer[15] == 1)
strRes += "<br>Question 16: Correct<br>";
else{
strRes += "<br>Question 16: Wrong<br>";
strNextQ += "16";
}
if(aAnswer[16] == 1)
strRes += "<br>Question 17: Correct<br>";
else{
strRes += "<br>Question 17: Wrong<br>";
strNextQ += "17";
}
if(aAnswer[17] == 1)
strRes += "<br>Question 18: Correct<br>";
else{
strRes += "<br>Question 18: Wrong<br>";
strNextQ += "18";
}
if(aAnswer[18] == 1)
strRes += "<br>Question 19: Correct<br>";
else{
strRes += "<br>Question 19: Wrong<br>";
strNextQ += "19";
}
if(aAnswer[19] == 1)
strRes += "<br>Question 20: Correct<br>";
else{
strRes += "<br>Question 20: Wrong<br>";
strNextQ += "20";
}if(rights < aAnswer.length/2){ // Go to Redo Quiz
strRes += "<br><br><br>Quiz Failed !! Restart Quiz ?";
strRes += "<a href='Level3.html'><br><br>YES</a>" + " ";
strRes += "<a href='closewin3.html'> NO</a>" + " ";
//Send the strNextQ to file LogLevel3.asp
url = "LogLevel3.asp?Action=NextQ&QNo=" + strNextQ,false;
objXmlHTTP.open("POST", url ,false);
objXmlHTTP.send("");document.write(strRes); //Show result
}
if(aAnswer.length/2 <= rights){
strRes += "<br><br>End Quiz ? ";
strRes += "<a href='end3.html'><br><br>YES</a>" + " ";
strRes += "<a href=''>NO</a>" + " ";
}
//Send the The no. of correct to LogLevel3.asp
url = "LogLevel3.asp?Action=NextQ&QNo=" + rights,false;
objXmlHTTP.open("POST", url ,false);
objXmlHTTP.send("");document.write(strRes); //Show result
}
var timeCount = 0;
function timer(){
timeCount++; //increment the time by one second//to display the time in the status bar,
// uncomment the next line
//window.status = "..." + timeCount + " secs" ;//to display the time
temp = "Time: " + parseInt(timeCount/60);
temp += " min : " + (timeCount%60) + " sec " ;
TBlock.innerText = temp;//if the time is up
if (timeCount == QuizDuration) {
alert("Sorry, The Time Is Up");
showResult();
}
}
</script><body>
<h2 align=center>Online Quiz 3</h2><form name=frm >
<table border=1 width=95% bgcolor=skyblue align=center height="26">
<tr><td align=right height="19"><b id=TBlock></b></td></tr>
<tr><td height="1">
<p id="QArea">
<center>
<br>
There are ONLY 1 attempt in this level. 20 questions are given.
<br>
Durations for this attempt is 25 minutes.
<br>
Good Luck !!
<br>
<br>
<input type=button name=btnFinish value="Begin Quiz" onClick="init()">
</center>
</p>
<input type=hidden name=ansNo>
</td></tr></table>
</form></body>
</html>-
ASP File:
<%
Response.expires = 0
'create an instance of MS XMLDOM Object
'and load the Questions.xml file where all the questions are.set obj = server.createobject("Microsoft.XMLDOM")
obj.async = false
obj.load(Server.MapPath("Level3Questions.xml"))
'very first request from the client
if trim(request("Action")) = "Start" then
'set no of questions per exam
Dim TotalQ
'count no of questions in the xml file
'( or from database)
TotalQ = obj.selectNodes("data/question").lengthDim aQuest(),temp,isExist,strQ
ReDim aQuest(0) 'to store the question ids
strQ = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"
'send the question in the strQ to the client
response.write strQ
'all further requests - after the first request
elseif trim(request("Action")) = "NextQ" then
'fetch the question from the XML Object
'and form the output string
temp = "data/question[@id=" & trim(request("QNo")) & "]"set Node = obj.selectSingleNode(temp)
strXML = "<data>"
strXML = strXML & "<qtext>"
strXML = strXML & Node.selectSingleNode("qtext").text
strXML = strXML & "</qtext>"
strXML = strXML & "<answer>"
strXML = strXML & Node.selectSingleNode("answer").text
strXML = strXML & "</answer>"set Node = Node.selectNodes("choices/choice")
for i = 0 to Node.length-1
strXML = strXML & "<choice>"
strXML = strXML & Node.item(i).text
strXML = strXML & "</choice>"
nextstrXML = strXML & "</data>"
'send the output to the client
Response.Write (strXML)end if
%>-
HTML File
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">function closewindow() {
self.opener = this;
self.close();
}
</SCRIPT>
</head>
<body>
<h2 align=center>Online Quiz 3</h2><form name=frm >
<table border=1 width=95% bgcolor=skyblue align=center height="26">
<tr><td align=right height="19"><b id=TBlock></b></td></tr>
<tr><td height="1">
<p id="QArea">
<center>
<br>
You have ended the quiz.
<br>
<br>
<a href="Level3.html">Restart Quiz</a>
<p><a href="blank.html" onClick="closewindow()">Close Window</a>
</center>
</p>
<input type=hidden name=ansNo>
</td></tr></table>
</form></body>
</html>-
HTML File
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">function closewindow() {
self.opener = this;
self.close();
}
</SCRIPT>
</head>
<body>
<h2 align=center>Online Quiz 3</h2><form name=frm >
<table border=1 width=95% bgcolor=skyblue align=center height="26">
<tr><td align=right height="19"><b id=TBlock></b></td></tr>
<tr><td height="1">
<p id="QArea">
<center>
<br>
You have ended the quiz.
<br>
<br>
<a href="blank.html" onClick="closewindow()">Close Window</a>
</center>
</p>
<input type=hidden name=ansNo>
</td></tr></table>
</form></body>
</html>-
Database File ( file name:mydatabase.mdb, Table name:Test, Table have 2column namely Results and QNo)
<%@ Language="VBScript" %>
<% Option Explicit %>
<%
'declare the dimension variables
Dim rs, student, Conn'declare the statement that will query the database
student="INSERT INTO Test ([AssNo], [Result], [QNo])"'define the connection string, specify database driver and the location of database
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb")
'create an ADO connection object
Set rs = Server.CreateObject("ADODB.Recordset")
'Open the connection to the database
rs.Open(Conn)'execute the statement that will query the database
rs.execute(student)'Write to database
Response.Write ("<br>")
Response.Write (rs('"&AssNo&"'))
Response.Write ("<br>")
Response.Write (rs('"&Result&"'))
Response.Write ("<br>")
Response.Write (rs('"&QNo&"'))
Response.Write ("<br>")'close database
Response.Closers.MoveNext
'close the object and free up resources
rs.Close
Set rs = Nothing
Set Conn = Nothing
%>-
My Quiz Question .xml File
<?xml version="1.0"?>
<data>
<question id="1">
<qtext>What is the Output for a AND Gate if both Input is '1'</qtext>
<choices>
<choice>1</choice>
<choice>0</choice>
<choice>11</choice>
<choice>None of Above</choice>
</choices>
<answer>1</answer>
</question>
<question id="2">
<qtext>Find the 2's complement of 101001</qtext>
<choices>
<choice>010111</choice>
<choice>010110</choice>
<choice>110000</choice>
<choice>110111</choice>
</choices>
<answer>1</answer>
</question>
<question id="3">
<qtext>0100 0101 + 83D =? left your answer in Decimal.</qtext>
<choices>
<choice>182</choice>
<choice>128</choice>
<choice>152</choice>
<choice>125</choice>
</choices>
<answer>3</answer>
</question>
<question id="4">
<qtext>245D + 36H =? left your answer in Hexadecimal </qtext>
<choices>
<choice>281H</choice>
<choice>12BH</choice>
<choice>27BH</choice>
<choice>133H</choice>
</choices>
<answer>2</answer>
</question>
<question id="5">
<qtext>Which of the following is the most widely used code for computer input and output?</qtext>
<choices>
<choice>EBCDIC</choice>
<choice>ECC</choice>
<choice>Excess-3</choice>
<choice>ASCII</choice>
</choices>
<answer>4</answer>
</question>
<question id="6">
<qtext>1100 - 0111 = ? (using direct subtraction.)</qtext>
<choices>
<choice>0110</choice>
<choice>1110</choice>
<choice>0010</choice>
<choice>0101</choice>
</choices>
<answer>4</answer>
</question>
<question id="7">
<qtext>What is the Output for a Nand Gate if both Input is '1'</qtext>
<choices>
<choice>11</choice>
<choice>0</choice>
<choice>1</choice>
<choice>None of above</choice>
</choices>
<answer>2</answer>
</question>
<question id="8">
<qtext>0011 0101 0100 + 12H =? left your answer in Hexadecimal.</qtext>
<choices>
<choice>366</choice>
<choice>357</choice>
<choice>356</choice>
<choice>376</choice>
</choices>
<answer>1</answer>
</question>
<question id="9">
<qtext>Find the 2's complement of 100100</qtext>
<choices>
<choice>100100</choice>
<choice>011100</choice>
<choice>011011</choice>
<choice>011000</choice>
</choices>
<answer>2</answer>
</question>
<question id="10">
<qtext>ABC * 1 = ?</qtext>
<choices>
<choice>1</choice>
<choice>ABC</choice>
<choice>0</choice>
<choice>none of above</choice>
</choices>
<answer>2</answer>
</question>
<question id="11">
<qtext>What is the Output for a AND Gate if both Input is '1'</qtext>
<choices>
<choice>1</choice>
<choice>0</choice>
<choice>11</choice>
<choice>None of Above</choice>
</choices>
<answer>1</answer>
</question>
<question id="12">
<qtext>Find the 2's complement of 101001</qtext>
<choices>
<choice>010111</choice>
<choice>010110</choice>
<choice>110000</choice>
<choice>110111</choice>
</choices>
<answer>1</answer>
</question>
<question id="13">
<qtext>0100 0101 + 83D =? left your answer in Decimal.</qtext>
<choices>
<choice>182</choice>
<choice>128</choice>
<choice>152</choice>
<choice>125</choice>
</choices>
<answer>3</answer>
</question>
<question id="14">
<qtext>245D + 36H =? left your answer in Hexadecimal </qtext>
<choices>
<choice>281H</choice>
<choice>12BH</choice>
<choice>27BH</choice>
<choice>133H</choice>
</choices>
<answer>2</answer>
</question>
<question id="15">
<qtext>Which of the following is the most widely used code for computer input and output?</qtext>
<choices>
<choice>EBCDIC</choice>
<choice>ECC</choice>
<choice>Excess-3</choice>
<choice>ASCII</choice>
</choices>
<answer>4</answer>
</question>
<question id="16">
<qtext>1100 - 0111 = ? (using direct subtraction.)</qtext>
<choices>
<choice>0110</choice>
<choice>1110</choice>
<choice>0010</choice>
<choice>0101</choice>
</choices>
<answer>4</answer>
</question>
<question id="17">
<qtext>What is the Output for a Nand Gate if both Input is '1'</qtext>
<choices>
<choice>11</choice>
<choice>0</choice>
<choice>1</choice>
<choice>None of above</choice>
</choices>
<answer>2</answer>
</question>
<question id="18">
<qtext>0011 0101 0100 + 12H =? left your answer in Hexadecimal.</qtext>
<choices>
<choice>366</choice>
<choice>357</choice>
<choice>356</choice>
<choice>376</choice>
</choices>
<answer>1</answer>
</question>
<question id="19">
<qtext>Find the 2's complement of 100100</qtext>
<choices>
<choice>100100</choice>
<choice>011100</choice>
<choice>011011</choice>
<choice>011000</choice>
</choices>
<answer>2</answer>
</question>
<question id="20">
<qtext>ABC * 1 = ?</qtext>
<choices>
<choice>1</choice>
<choice>ABC</choice>
<choice>0</choice>
<choice>none of above</choice>
</choices>
<answer>2</answer>
</question>
</data> -
Post a reply
MS Access forum discussion
-
is it possible to create exe file for access file
by swiftprosoftware.dm (17 replies)
-
Print an invoice
by cogniscient (3 replies)
-
Showing One Record of a Subform
by smita.patil (0 replies)
-
printing images in acces report
by jbarrios (0 replies)
-
Highlighting Text field for input
by sad1121 (0 replies)
Quick links
Recent activity
- arif ahmad replied to How to receive data in web ...
- William Thompson replied to What is the name of the Win...
- Sameera Piyadigamage replied to Point of Sale Developers: H...
- Scott Carline replied to 4 x C# Developers for large...
- Rajendra Dhakal replied to Restore SQL Server text dat...
- cloud rainda replied to How to convert between TS f...
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).