php - 无法使用 PHP echo 创建的表单接收 post 参数

标签 php mysql

我正在制作一个允许您添加 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/

相关文章:

php - 处理日期

mysql - 我应该在 ubuntu Natty Narwhal 中安装哪个版本的 percona db 包?

mysql - 查找多个表的费率低于平均费率

php - 在 php 中从 Markdown 生成目录

php - 递归地搜索数组中的键

javascript - 尝试 Ajax

php - 重命名 javascript 对象以使用 php 数组

mysql - sql中两个表的列求和

php - 在同一页面上用 php 更新和选择如何

MySQL 如果子查询中的记录 AND 1 字段未设置或根本不在子查询中