选择表单中的未定义索引

时间:2015-06-29 05:32:03

标签: php

当我点击提交时,它给了我一个错误,“未定义索引:选择”不知道为什么我认为我做的一切都是正确的,我使它类似于我连接到数据库的其他一些页面。选择是在DB中,我在IF语句中定义它,有人可能会在我的问题上找到一些明显的亮点吗?

<form action="login_success.php" method="POST">
<?php
    if(isset($_POST['submitbtn'])) {
        $selection = $_POST['selection']; 
        mysql_query("INSERT INTO users (selection) VALUE ('$selection')");
    }   
?>

    <fieldset>
    <legend>Pick</legend>
        <select id="tm1" name="teams">
        <?php
        $tt = date("H");

        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '     <option value="wr"'.$dis.'>Washington Redskins</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="nyg"'.$dis.'>New York Giants</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="pe"'.$dis.'>Philadelphia Eagles</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="dc"'.$dis.'>Dallas Cowboys</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="br"'.$dis.'>Baltimore Ravens</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="ps"'.$dis.'>Pittsburgh Steelers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="tt"'.$dis.'>Tennessee Titans</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="gbp"'.$dis.'>Green Bay Packers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="ss"'.$dis.'>Seattle Seahawks</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="cbr"'.$dis.'>Cleveland Browns</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="bb"'.$dis.'>Buffalo Bills</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="jj"'.$dis.'>Jacksonville Jaguars</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="ic"'.$dis.'>Indianapolis Colts</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="ht"'.$dis.'>Houston Texans</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="kcc"'.$dis.'>Kansas City Chiefs</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="md"'.$dis.'>Miami Dolphins</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="nep"'.$dis.'>New England Patriots</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="nyj"'.$dis.'>New York Jets</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="slr"'.$dis.'>Saint Louis Rams</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="nos"'.$dis.'>New Orleans Saints</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="mv"'.$dis.'>Minnesota Vikings</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="tbb"'.$dis.'>Tampa Bay Buccaneers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="ac"'.$dis.'>Arizona Cardinals</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="af"'.$dis.'>Atlanta Falcons</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="sf49"'.$dis.'>San Francisco 49ers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="sdc"'.$dis.'>San Diego Chargers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="or"'.$dis.'>Oakland Raiders</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="db"'.$dis.'>Denver Broncos</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="cbe"'.$dis.'>Cincinnati Bengals</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="cp"'.$dis.'>Carolina Panthers</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="dl"'.$dis.'>Detroit Lions</option>';
        if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = '';}echo '<option value="cbea"'.$dis.'>Chicago Bears</option>';
        ?>

        </select>
        <br>
    <input type="submit" value="submit" name="submitbtn">
    </fieldset>
</form>

2 个答案:

答案 0 :(得分:0)

实际上,您尝试访问的$_POST['selection']的值未设置,并且由于它正在投掷Notice: Undefined Index ...

答案 1 :(得分:0)

$selection = $_POST['selection'];应为$selection = $_POST['teams'];

<select id="tm1" name="teams">应为<select id="tm1" name="selection">

换句话说,表单元素和$_POST数组索引之间应该保持一致。