douhu2890 2015-06-30 04:40
浏览 28
已采纳

Firefox没有$ _POST所有重复的区域值,它只发布最后一个

So the code posted below work fine in Internet Explorer but not in Firefox. When passing the URL variable UserName Firefox only uses the last record in the record-set regardless of which button is chosen. This page uses a repeating region in order to allow a site administrator to set passwords, update user profiles, and delete users by clicking on individual buttons within each region. What should happen is that when a button is clicked it should forward you to the corresponding page with that regions UserName value included on the end of the URL. The issue is within Firefox only. $_POST['UserName'] always equals the value of the last created record in the SQL database. I am pretty new to PHP so I am not sure what I am overlooking here. None of my searches have been any help.

Here is the PHP:

<?php
$query_ManageUsers =$dbh->prepare("SELECT * FROM users WHERE UserLevel = 0 ORDER BY UserName ASC");
$query_ManageUsers->execute();
$row_ManageUsers = $query_ManageUsers->fetch(PDO::FETCH_ASSOC);
$query_RowCount = $dbh->prepare("SELECT COUNT(*) FROM users");
$totalRows_ManageUsers = $query_RowCount->fetchColumn();

if ((isset($_POST['UserID'])) && ($_POST['UserID'] != ""))
{
    $userName = $_POST['UserName'];
    switch ($_REQUEST['admin'])
    {
        case "Reset Password":
            $redirect = "SetPassword.php?UserName=$userName";
            header(sprintf("Location: %s", $redirect));break;
        case "Update Profile":
            $redirect = "UpdateUserProfile.php?UserName=$userName";
            header(sprintf("Location: %s", $redirect));break;
        case "Delete User":
            $redirect = "ConfirmDelete.php?UserName=$userName";
            header(sprintf("Location: %s", $redirect));break;
    }
}
?>

And here is the HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html: charset=utf-8"/>
<title>Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script language="JavaScript" type="text/javascript">document.documentElement.className="xr_bgh2";</script>
<link rel="stylesheet" type="text/css" href="index_htm_files/xr_main.css"/>
<link rel="stylesheet" type="text/css" href="index_htm_files/xr_text.css"/>
<link rel="stylesheet" type="text/css" href="index_htm_files/custom_styles.css"/>
<script type="text/javascript" src="index_htm_files/roe.js"></script>
</head>
<body class="xr_bgb2">
<div style="width:625px;">
<label style="text-align:left; font-size:18px; font-weight:bold;" >User Administration</label>
<?php if ($row_ManageUsers != 'null') { // Show if recordset not empty ?>
<?php do { ?>
<table border="1">
    <tr>
    <td>
    <form id="ManageUsers" method="post" >
        <table width="615">
        <tr>
        <td style="width:250px">
        <input name="UserName" style="width:250px; background-color:#C8DACA; border:none; font-size:14px" id="UserName" value="<?php echo $row_ManageUsers['UserName']; ?>" readonly="readonly" /></td>
         <td style="width:100px">
         <input name="admin" type="submit" value="Reset Password" form="ManageUsers" /></td>
         <td style="width:100px">
         <input name="admin" type="submit" value="Update Profile" form="ManageUsers" /></td>
         <td style="width:100px">
         <input name="UserID" type="hidden" id="UserID" form="ManageUsers" value="<?php echo $row_ManageUsers['UserID']; ?>" />
         <input name="admin" type="submit" value="Delete User" form="ManageUsers"/>
         </td>
         </tr>
     </table>
  </form>
</td>
</tr>
</table>
<?php } while ($row_ManageUsers = $query_ManageUsers->fetch(PDO::FETCH_ASSOC)); ?>
<?php } // Show if recordset not empty ?>
</div>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dpr77335 2015-06-30 04:52
    关注

    As I mentioned in the comments the issue is that your form(s) have the same ID, if you look at your html/php code you will notice that the whole form is output for each loop, and that includes the same id for each iteration of the loop.

    Some browsers will ignore this others may just use the last occurrence of the ID.

    Without testing this I cant be 100% sure that is the issue, but it's bad practice at the least and should be fixed.

    I would suggest using a unique id or even using that id as a class instead.

    Just to clarify, when I said form id I mean this

     <form id="ManageUsers" method="post" > 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加