0

我在我的 HTML 表单中设置了以下内容。如何在我的 PHP 页面中检索它(ON Submit)?

foreach ($rows as $i => $value) {
    echo "<br/>What do you think about : ";
    echo "<li>$value<br/>";
    echo "1<input type='radio' value='1' name='answer-$i' />&nbsp;";
    echo "2<input type='radio' value='2' name='answer-$i' />&nbsp;";
    echo "3<input type='radio' value='3' name='answer-$i' />&nbsp;";
    echo "4<input type='radio' value='4' name='answer-$i' />&nbsp;";
    echo "5<input type='radio' value='5' name='answer-$i' />&nbsp;";    
    }
?>

如何找回我的答案?

我对我的表单使用 POST 方法。帮我!!

添加详细信息。

<?php
echo "hello";
$answer = _POST("answer");
echo $answer-0;
echo $answer[0];
foreach ($answer as $i => $value) {

    echo $value;
    echo $i;
}

?>

答案-0=3&answer-1=1

以上值表明参数已设置(获取方法)。但在 POST 方法中,我无法访问它们。

有人能帮我吗?我还没有解决这个问题。

4

2 回答 2

0

所以你需要使用$_POST带方括号的数组(它是一个数组)。$answers假设您仍然$rows可用,此代码将为您构建一个数组。

$answers = array();
foreach ($rows as $i => $value) {
    $answers[$i] = $_POST["answer-$i"];
}
print_r($answers);
于 2013-04-11T23:26:27.287 回答
0
<form method="post">
<?php

foreach ($_POST as $i => $value) {
    echo "$i&nbsp;$value<br/>";
}

echo $_POST['answer-1'];
echo "<br>";
echo $_POST['answer-2'];

$rows = array(
    "1" => "bar",
    "2" => "foo",
);

foreach ($rows as $i => $value) {
    echo "<br/>What do you think about : ";
    echo "<li>$value<br/>";
    echo "1<input type='radio' value='1' name='answer-$i' />&nbsp;";
    echo "2<input type='radio' value='2' name='answer-$i' />&nbsp;";
    echo "3<input type='radio' value='3' name='answer-$i' />&nbsp;";
    echo "4<input type='radio' value='4' name='answer-$i' />&nbsp;";
    echo "5<input type='radio' value='5' name='answer-$i' />&nbsp;";    
    }
?>
<input type="submit"/>
</form>

看起来更像,你需要什么。

于 2013-04-12T04:15:36.737 回答