我有一个下拉菜单,并提交喜欢这个岗位后,在顶部的页面定义它:未定义指数
if ($_SERVER['REQUEST_METHOD' ] == 'POST') {
$usertype = clean($_POST['usertype']);
$useroption = array('admin', 'author', 'public');
,并在我这里形式的代码:
<tr>
<td><label for="usertype">User Type</label></td>
<td><select name="usertype" id="usertype">
<option disabled selected>Please choose the user right</option>
<?php foreach($useroption as $val): ?>
<option
value="<?php echo $val; ?>"
<?php echo (isset($error, $usertype) && $usertype == $val) ? 'selected="selected"' : ''; ?>
>
<?php echo ucfirst($val); ?>
</option>
<?php endforeach; ?>
</select></td>
</tr></form>
,但我得到的消息请注意:未定义指数:用户类型在E:\的EasyPHP \ DATA \ localweb \项目\伽玛\在此我的脚本插件user.php的第20行的:
$usertype = clean($_POST['usertype']);
请帮我看哪个代码或者我错过了导致这个问题的原因
我已经尝试删除我的clean函数,但结果仍然是一样的。但以防万一你想知道我的干净的代码,那么这就是:
function clean($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data, ENT_QUOTES);
$data = str_replace(array("<strong>", "</strong>"), array("<strong>", "</strong>"), $data);
return $data;
}
您确定,您通过'usertype'中的'POST'发送了一些内容吗?用'print_r($ _ POST);'或'print_r($ _ REQUEST);'检查它。 – loveNoHate
好的,我会尝试打印它 – Kyo
对不起,错别字。 ;) – loveNoHate