我显然错过了一些东西。
当我尝试使用POST方法从表单发布并且var_dumping结果时,如果var_dump向我显示包含表单数据的数组,那么我没有得到任何结果吗?
到目前为止,这是我的代码:
<?php
include "./includes/config.php";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
//mysql_query("");");
header('Location: ./manage_adduser.php');
exit();
}
?>
</head>
<body>
<?php var_dump($_POST); ?>
<div class="adminWrapper">
<div class="adminContentWrapper">
<h1><b>Add a User</b></h1>
<div class="list">
<table class="addNewTable">
<tr>
<td class="addNewLabelRow">
<form method="POST" action="">
<label>User privileges: </label>
</td>
<td class="addNewFieldRow">
<select name="newUserLevel">
<option value=\"1\" >(1) Standard User</option>
<option value=\"2\" >(2) Moderator</option>
<option value=\"3\" >(3) Admin</option>
</select>
</td>
</tr>
<tr>
<td class="addNewLabelRow">
<label>User Login Name: </label>
</td>
<td class="addNewFieldRow">
<input type="name" name="newUserLogin" value="">
</td>
</tr>
<tr>
<td class="addNewLabelRow">
<label>Users Full Name: </label>
</td>
<td class="addNewFieldRow">
<input type="name" name="newUserName" value="">
</td>
</tr>
<tr>
<td class="addNewLabelRow">
<label>Users e-mail address: </label>
</td>
<td class="addNewFieldRow">
<input type="email" name="newUserEmail" value="">
</td>
</tr>
</table>
</div>
<div class="list">
<table class="addNewTable">
<tr>
<td class="addNewLabelRow">
<label>Password: </label>
</td>
<td class="addNewFieldRow">
<input type="password" name="newUserPassword" value="">
</td>
</tr>
<tr>
<td class="addNewLabelRow">
<label>Repeat Password: </label>
</td>
<td class="addNewFieldRow">
<input type="password" name="newUserPasswordRepeat" value="">
</td>
</tr>
</table>
</div>
</div>
<!-- BUTTONS -->
<div class="buttonWrap">
<input class="buttonAddNewGroup" type="submit" value=" Add User ">
</div>
答案 0 :(得分:6)
这是因为如果请求方法发布并且您丢失了POST内容,那么您将重定向浏览器。
评论这一部分:
if ($_SERVER["REQUEST_METHOD"] == "POST"){
//mysql_query("");");
header('Location: ./manage_adduser.php');
exit();
}
和var_dump($_POST)
看起来会有所不同。
答案 1 :(得分:2)
var_dump
未执行,因为您在该语句之前退出代码:
if ($_SERVER["REQUEST_METHOD"] == "POST"){
/* … */
exit();
}