php - 在mysql中提交多个和单个提交按钮

标签 php html mysql

我正在尝试使用 php 和 mysql 进行在线测验/调查!我是第一次使用 php! 我想做的是从我的数据库中获取问题及其多个选择(以 Qid、Qtext、Ans1..Ans4 作为 6 列的测验和表格问题),一旦用户完成测验 n 就按最后的“提交”按钮问题..所有答案都应该保存在Db中(测验和表格答案,以Aid、Ans、Qid为列)!我搜索了相关代码但无法理解其中任何一个。 如果有人能提供帮助,我将不胜感激。 谢谢。

最佳答案

在 View 中将输入作为数组,例如:

<input type="text" name="answer[]" />
<input type="text" name="answer[]" />
<input type="text" name="answer[]" />

提交后,

$answers = $_POST['answer'];

foreach($answers as $answer)
{
   ...
}

关于php - 在mysql中提交多个和单个提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19197640/

相关文章:

php - 将类属性值移动到 php 变量

mysql - "replace into"仅当新记录具有新时间戳时

php - 如何在 symfony 表单上隐藏单个标签?

php - MySQL密码检查器

jquery - 使用 jQuery .addClass 和 .removeClass 的 CSS3 过渡

python - mysql错误: ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)

mysql - MySQL 中良好的一对多关系实践

PHP - 何时在类中使用私有(private)静态属性

php - 外键 "can not add or update a child row"

javascript - 渲染 html 时不显示 maxlength 属性?