有点帮助使用php将html测验表格数据发送到mysql数据库 [英] A little help sending html quiz form data to mysql db using php

查看:70
本文介绍了有点帮助使用php将html测验表格数据发送到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我在这里很新,但到目前为止我喜欢你们的专业知识。我正在同时学习html,mysql和php基础知识。我目前的任务是在线创建一个简单的测验表格。每个问题在mysql的问题表中都有一个唯一的id。还有一个答案表和一个小部件表。

一个问题可以有多个答案,但每个答案只有一个问题。一个问题可以有只有一种小部件类型(选择了一个小部件类型,文本区域等,用于其应答模式。)

到目前为止,我已经在数据库中创建了主键和外键的表。例如。

答案和小部件表都有一个question_id字段,引用问题表中的question_id(PK,自动增量)。

我觉得具有挑战性的部分是如何创建一个合适的html表单,可以在问题表中插入一个问题,同时在answer和widgets表中插入question_id?

我似乎无法获得sql查询好吧,甚至html表单本身也不太对。我真的很感谢你们的帮助。以下是我到目前为止所尝试的内容:

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>
	<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>

推荐答案

表1将包含一个唯一ID - 主键和问题。

表2将包含一个唯一ID - 外键和可能的解决方案





然后SQL查询将检查表,如果解决方案正在尝试该问题不等于可能的解决方案然后显示错误
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


这篇关于有点帮助使用php将html测验表格数据发送到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆