我正在制作一个允许您添加 friend 的网页。对于确认部分,我制作了一个确认按钮,将帖子重定向到确认页面:
while($rs=$friendsToConfirm->fetch_row()) {
echo "Friends $count to confirm's ID: $rs[0]";
echo "
<form name=\"confirm\" method=\"post\" action=\"confirmfriend.php\">
<input type=\"hidden\" name=\"userID\" value=\"$userID\">
<input type=\"hidden\" name=\"friendID\" value=\"$rs[0]\">
<input type=\"submit\" value=\"Confirm\">
</form>
";
echo "<br>";
$count++;
}
$friendToConfirm
变量是需要确认的所有好友,并从 MySQL 中检索。当我点击按钮时,我预计会从confirmfriend.php收到userID和friendID,但我没有使用$_POST['userID'];
收到任何信息。有其他方法可以做到这一点还是我做错了什么。
最佳答案
这是因为您的所有表单都具有相同的名称 [confirm]。你可以试试这个:
$sl = 1;
while($rs=$friendsToConfirm->fetch_row()) {
echo "Friends $count to confirm's ID: $rs[0]";
echo "
<form name=\"confirm{$sl}\" method=\"post\" action=\"confirmfriend.php\">
<input type=\"hidden\" name=\"userID\" value=\"$userID\">
<input type=\"hidden\" name=\"friendID\" value=\"$rs[0]\">
<input type=\"submit\" value=\"Confirm\">
</form>
";
echo "<br>";
$count++;
$sl++;
}
希望这会起作用。
关于php - 无法使用 PHP echo 创建的表单接收 post 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35240563/