I am a beginner in the world of HTML, PHP, JavaScript, and MySQL. I have developed a quiz using JavaScript and HTML, but now I believe I need a database to store all the questions and answers. I am currently using PHPMyAdmin to set up the database and tables.
The quiz I have created is a type quiz, similar to a "What type of ____ are you?" quiz (e.g., color, dog, personality) where there is no one correct answer to each question.
I am uncertain about what exactly needs to be included in my database for the quiz to function properly. I can provide you with a basic layout of my code if that would be helpful. I apologize if my explanation is unclear.
JavaScript
<head>
<title>Questions</title>
<script language="Javascript">
function process()
{
var Ans1 = 0;
var Ans3 = 0;
var Ans4 = 0;
var Ans2 = 0;
var f = document.f;
var i = 0;
for (i = 0; i < f.q1.length; i++) if (f.q1[i].checked) value = f.q1[i].value;
if (value == "1") { Ans3++; } <!--put in order with least likely answer first-->
if (value == "2") { Ans4++; }
if (value == "3") { Ans2++; }
if (value == "4") { Ans1++; }
for (i = 0; i < f.q2.length; i++) if (f.q2[i].checked) value = f.q2[i].value;
if (value == "1") { Ans3++; } <!--put in order with least likely answer first-->
if (value == "2") { Ans4++; }
if (value == "3") { Ans2++; }
if (value == "4") { Ans1++; }
for (i = 0; i < f.q3.length; i++) if (f.q3[i].checked) value = f.q3[i].value;
if (value == "1") { Ans3++; } <!--put in order with least likely answer first-->
if (value == "2") { Ans4++; }
if (value == "3") { Ans2++; }
if (value == "4") { Ans1++; }
...
var out = "Ans1";
i = Ans1;
if (Ans4 > i) { out ="Ans4"; i = Ans4; }
if (Ans3 > i) { out ="Ans3"; i = Ans3; }
if (Ans2 > i) { out ="Ans2"; i = Ans2; }
location.href = out + ".shtml";
}
function err(msg, url, line)
{
location.href = "error.html";
}
//window.onerror = err;
// -->
</script>
</head>
HTML Quiz Question/Answer Options
<body>
<?php include ('SiteMenu'); ?>
Answer the questions below...
<form name="f">
<b>What is your answer to question #1?<br></b>
<input type="radio" name="q1" value="4">Ans1.<br>
...
Thank you for taking our quiz! <br>
<input type="button" value="Find my Result!" onclick="process();"><br><br>
</form>
</body>
</html>
UPDATE: I am trying to understand how to set up the database. This is what I have in mind: I have 2 tables: questions and answers The questions table looks like:
qID aID qText
q1 What is your favorite color?
q2 This is the second question
and so on
Then, the answers table is structured as follows:
qID valID aText
q1 Green
q1 Blue
q1 Red
q2 question 2 answer choice1
q2 question 2 answer choice2
and so on