2014-12-26 141 views
0

我有一个下拉菜单,并提交喜欢这个岗位后,在顶部的页面定义它:未定义指数

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("&lt;strong&gt;", "&lt;/strong&gt;"), array("<strong>", "</strong>"), $data); 
    return $data; 
} 
+0

您确定,您通过'usertype'中的'POST'发送了一些内容吗?用'print_r($ _ POST);'或'print_r($ _ REQUEST);'检查它。 – loveNoHate

+0

好的,我会尝试打印它 – Kyo

+0

对不起,错别字。 ;) – loveNoHate

回答

1

没有任何用户类型指数$_POST[]这样尝试

$usertype = (isset($_POST['usertype']) ? clean($_POST['usertype']) :''); 
+0

它的工作,但为什么?与此同时另一个人不会给这些问题带来甚至是空的? – Kyo

+0

检查您的发布数据和表单字段名称是否正确print_r($ _ POST) –

+0

是的,我已经做到了,它没有被发送?这是我在这里错过的东西吗? – Kyo

0

的变化选项的检查到这一点:

  <option selected >Please choose the user right</option>