Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php表单的多个单选按钮数组_Php_Html_Arrays_Forms_Radio Button - Fatal编程技术网

php表单的多个单选按钮数组

php表单的多个单选按钮数组,php,html,arrays,forms,radio-button,Php,Html,Arrays,Forms,Radio Button,我是新来的。我正在研究web开发,必须为问卷创建一个php响应表单,然后将其输入数据库。我的单选按钮有问题。我无法创建生成数组并在响应表单/页面中显示答案的正确代码 这是我的代码: <form name="modulequestionnaire" method="post" action="tania.responseform.php" /> <p><i>Rate each question from 6 to 1, six being strongly

我是新来的。我正在研究web开发,必须为问卷创建一个php响应表单,然后将其输入数据库。我的单选按钮有问题。我无法创建生成数组并在响应表单/页面中显示答案的正确代码

这是我的代码:

<form name="modulequestionnaire" method="post" action="tania.responseform.php" />

<p><i>Rate each question from 6 to 1, six being strongly 
agree and one being strongly disagree.</i></p>

1. I think the module guide/student handbook provided enough information about the 
module content, organisation and assessment.<br/>

6<input type="radio" name="answer[1]" value="6"> 5<input type="radio" name="answer[1]" value="5"> 
4<input type="radio" name="answer[1]" value="4"> 3<input type="radio" name="answer[1]" value="3"> 
2<input type="radio" name="answer[1]" value="2"> 1<input type="radio" name="answer[1]" value="1">
</p>

2.The module was well organised.<br/>

6<input type="radio" name="answer[2]" value="6"> 5<input type="radio" name="answer[2]" value="5"> 
4<input type="radio" name="answer[2]" value="4"> 3<input type="radio" name="answer[2]" value="3"> 
2<input type="radio" name="answer[2]" value="2"> 1<input type="radio" name="answer[2]" value="1"> 
</p>

3.The Learning Resource Centre provided adequate materials for the module.<br/>

6<input type="radio" name="answer[3]" value="6"> 5<input type="radio" name="answer[3]" value="5"> 
4<input type="radio" name="answer[3]" value="4"> 3<input type="radio" name="answer[3]" value="3"> 
2<input type="radio" name="answer[3]" value="2"> 1<input type="radio" name="answer[3]" value="1"> 
</p>

将每个问题从6分到1分,其中6分为强
同意和强烈反对

1.我认为模块指南/学生手册提供了关于 模块内容、组织和评估。
6 5 4 3 2 1

2.模块组织良好。
6 5 4 3 2 1

3.学习资源中心为模块提供了足够的材料。
6 5 4 3 2 1

我知道答案可能与isset函数有关,但我不知道如何对其进行编码。
有人可以在这里教我或帮助我吗?

当您不确定如何处理已设置的HTML标记时,您应该
var\u dump($\u POST)
发送到PHP处理程序页面的值,以便您知道格式是什么样的,这样您就可以从那里继续

当我创建HTML并使用
var\u dump
和一些随机选择测试它时,输出是

array(2) { ["answer"]=> array(3) { [1]=> string(1) "5" [2]=> string(1) "3" [3]=> string(1) "4" } ["submit"]=> string(6) "Submit" }
请注意,
$\u POST['answer']
变量中有一个数组。因此,您应该对该数组中的每个元素执行
foreach
,以处理每个相应的值:

foreach ($_POST['answer'] as $answer) {
    // do stuff with the answer
}
如果您需要使用在
POST
数组中定义的答案号码,您可以使用一个键
foreach

foreach ($_POST['answer'] as $answerNum => $answer) {
    // do stuff with $answerNum and $answer
}
当然,您可以通过其号码直接访问您的答案:

if (!empty($_POST['answer'][1])) { // To ensure that the value is being sent
    // do stuff with $_POST['answer'][1]
}

当您不确定如何处理已设置的HTML标记时,您应该
var\u dump($\u POST)
发送到PHP处理程序页面的值,以便知道格式是什么样的,这样您就可以从那里开始了

当我创建HTML并使用
var\u dump
和一些随机选择测试它时,输出是

array(2) { ["answer"]=> array(3) { [1]=> string(1) "5" [2]=> string(1) "3" [3]=> string(1) "4" } ["submit"]=> string(6) "Submit" }
请注意,
$\u POST['answer']
变量中有一个数组。因此,您应该对该数组中的每个元素执行
foreach
,以处理每个相应的值:

foreach ($_POST['answer'] as $answer) {
    // do stuff with the answer
}
如果您需要使用在
POST
数组中定义的答案号码,您可以使用一个键
foreach

foreach ($_POST['answer'] as $answerNum => $answer) {
    // do stuff with $answerNum and $answer
}
当然,您可以通过其号码直接访问您的答案:

if (!empty($_POST['answer'][1])) { // To ensure that the value is being sent
    // do stuff with $_POST['answer'][1]
}

我不认为这正是你想要做的。如果你给这三个问题取不同的名字:

<form name="modulequestionnaire" method="post" action="tania.responseform.php" />

<p><i>Rate each question from 6 to 1, six being strongly 
agree and one being strongly disagree.</i></p>

1. I think the module guide/student handbook provided enough information about the 
module content, organisation and assessment.<br/>

6<input type="radio" name="answer1" value="6"> 5<input type="radio" name="answer1" value="5"> 
4<input type="radio" name="answer1" value="4"> 3<input type="radio" name="answer1" value="3"> 
2<input type="radio" name="answer1" value="2"> 1<input type="radio" name="answer1" value="1">
</p>

2.The module was well organised.<br/>

6<input type="radio" name="answer2" value="6"> 5<input type="radio" name="answer2" value="5">



4<input type="radio" name="answer2" value="4"> 3<input type="radio" name="answer2" value="3"> 
2<input type="radio" name="answer2" value="2"> 1<input type="radio" name="answer2" value="1"> 
</p>

3.The Learning Resource Centre provided adequate materials for the module.<br/>

6<input type="radio" name="answer3" value="6"> 5<input type="radio" name="answer3" value="5"> 
4<input type="radio" name="answer3" value="4"> 3<input type="radio" name="answer3" value="3"> 
2<input type="radio" name="answer3" value="2"> 1<input type="radio" name="answer3" value="1"> 
</p>

我不认为这正是你想要做的。如果你给这三个问题取不同的名字:

<form name="modulequestionnaire" method="post" action="tania.responseform.php" />

<p><i>Rate each question from 6 to 1, six being strongly 
agree and one being strongly disagree.</i></p>

1. I think the module guide/student handbook provided enough information about the 
module content, organisation and assessment.<br/>

6<input type="radio" name="answer1" value="6"> 5<input type="radio" name="answer1" value="5"> 
4<input type="radio" name="answer1" value="4"> 3<input type="radio" name="answer1" value="3"> 
2<input type="radio" name="answer1" value="2"> 1<input type="radio" name="answer1" value="1">
</p>

2.The module was well organised.<br/>

6<input type="radio" name="answer2" value="6"> 5<input type="radio" name="answer2" value="5">



4<input type="radio" name="answer2" value="4"> 3<input type="radio" name="answer2" value="3"> 
2<input type="radio" name="answer2" value="2"> 1<input type="radio" name="answer2" value="1"> 
</p>

3.The Learning Resource Centre provided adequate materials for the module.<br/>

6<input type="radio" name="answer3" value="6"> 5<input type="radio" name="answer3" value="5"> 
4<input type="radio" name="answer3" value="4"> 3<input type="radio" name="answer3" value="3"> 
2<input type="radio" name="answer3" value="2"> 1<input type="radio" name="answer3" value="1"> 
</p>

您可以发布您现有的PHP尝试吗?@HC_u我想为上面的问题创建答案。@sjagr类似的东西,但它不起作用。请在您的问题中而不是在评论中发布您的尝试。人们也更容易阅读@taniakeira@Fred-ii-好的,对不起,我是新手。你能发布你现有的PHP尝试吗?@HC_u我想为上面的问题创建答案。@sjagr类似的东西,但它不起作用。请在你的问题中发布你的尝试,而不是在评论中。人们也更容易阅读@taniakeira@Fred-ii-好的,对不起,我是新手。这很有效,但源于OP需要学习创建和处理
POST
数组这一课的目的。使用
POST
数组编写代码特别有用,因为如果代码编写正确,那么在单个问题中添加的工作量就会减少。没错,我想我个人会远离POST数组,因为它们很快就会变得混乱。我只在接收不同数量的输入时才真正使用post数组,例如multiselect,但我不确定在这种情况下为什么要使用数组。除了为了上课。。。好的,你赢了这一轮:)这是有效的,但它源自OP需要学习的关于创建和处理
POST
数组的课程的目的。使用
POST
数组编写代码特别有用,因为如果代码编写正确,那么在单个问题中添加的工作量就会减少。没错,我想我个人会远离POST数组,因为它们很快就会变得混乱。我只在接收不同数量的输入时才真正使用post数组,例如multiselect,但我不确定在这种情况下为什么要使用数组。除了为了上课。。。好的,你赢了这一轮:)非常感谢你,先生。非常感谢你,先生。