Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi everyone.I'm quite new here but so far i like the expertise you guys have.I'm learning html,mysql and php basics all at the same time.My current task is creating a simple quiz form online.Each question has a unique id in the questions table on mysql.There is also an answers table and a widgets table.
A question can have multiple answers but each answer has only one question.A question can have only one widget type(a radio option,text area etc selected,for its answer mode.)
So far i have the tables with the primary and foreign keys created well in the database. eg.
answers and widgets tables both have a question_id field referencing the question_id(PK, auto increment) from the questions table.
The part which i find challenging is how to create a proper html form that will be able to insert a question to the questions table and at the same time insert the question_id in the answers and widgets tables?
I can't seem to get the sql query well and even the html form itself isn't quite right.I would really appreciate any help form you guys. Below is what i've tried so far :
HTML
<html>
	<head>
		<title> Create a new Survey </title>
		<script type="text/javascript" src="script.js"></script>
	</head>
		<body style= "background: #D1D0CE">

		 Create a new Survey
			<form action="insert.php"  method="post">

				Form Information
				(Please enter your form details below.)
				
					 Form Name  :  
					 <input type="text" size="12" maxlength="40"  name="formName"/>

					Date : 
					 <input type="date" size="12" maxlength="40"  name="formDate"/>
				Question Details
				 
 				 <input type="button" value="Add Question"  önClick="addRow('questionTable')" /> 
  				<input type="button" value="Remove Question"  önClick="deleteRow('questionTable')" /> 
				
						<input type="checkbox" name="chk[]"/>
						
							<label>Question : </label>
							<input type="text" size = "16" maxlength= "50"  name="description"/>
			
							<label>Input Type :</label>
							<select id="widgetType" name="widgetType" required="required">
								<option>....</option>
								<option>radio button</option>
								<option>check box</option>
								<option>Edit Text</option>
								<option>Spinner</option>
								<option>Rating bar</option>
								
							</select>
						
				Answer Details
					 
 				 <input type="button" value="Add Answer"  önClick="addAnswer('answerTable')" /> 
  				<input type="button" value="Remove Answer"  önClick="deleteAnswer('answerTable')" /> 
						(Click to add more answer options.)
                		
			
					 <input type="checkbox" name="chk[]"/>
						<label>Answer : </label>  
							<input type="text" size="12" maxlength="40"  name="answerText">

						
							<label>Match to Question :</label>
							<select id="QuestionNumber" name="question" required="required">
								<option>....</option>
								<option>Question 1</option>
								<option>Question 2</option>
								<option>Question 3</option>
								<option>Question 4</option>
								<option>Question 5</option>
								<option>Question 6</option>
								<option>Question 7</option>
								<option>Question 8</option>
								<option>Question 9</option>
								<option>Question 10</option>
								
							</select>
							

			<input type="submit" name="submit" value="Submit">
			</form>

		</body>
</html>
Posted
Updated 15-Nov-13 4:17am
v2

1 solution

Table 1 would consist of a Unique ID - Primary Key and the question.
Table 2 would consist of a Unique ID - Foreign Key and possible solution


The SQL query would then check against the tables, on which question it is being attempted, if the solution is not equal to the possible solution then display error
 
Share this answer
 
Comments
Member 9813435 17-Nov-13 3:54am    
hey @bmw318mt thank you for your response.I think your response is for questions which are already in the database though.My scenario is different the tables are empty and the html form and the sql query is what populates the tables with the questions and answers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900