-2
<?php
$sel1="";
$sel2="";
$suc="";
$male="";
$female="";
$selected_radio="";
if(isset($_POST['save']))
{
    $e=0;
    if(isset($_POST['sport']))
    {
        $select_sport=$_POST['sport'];
        if($_POST['sport']=="")
        {
            $sel1="<--Select The Game-->";
            $e=1;
        }
    }
    if(isset($_POST['gender']))
    {
        $selected_radio = $_POST['gender'];
    }
    else
    {
        $sel2="<--Select Your Gender-->";
        $e=1;
    }
if($e==0)
{
$suc="Success";
$male ="";
$female ="";
}
}
?>
<body>
<select name="sport">
<option value="">
<option value="cri" <?php if($select_sport=='cri') { echo "selected"; } ?>> CRICKET </option>
<option value="foot" <?php if($select_sport=='foot') { echo "selected"; }?>> FOOTBALL </option>
</select>

当我在浏览器上打开这个程序时,错误“未定义的索引”出现在选择选项(下拉框)中。

但是当我点击保存按钮时,错误消失了。当我不选择任何运动时,它工作得很好,它显示错误消息。


所以请帮助我找到解决方案...

4

1 回答 1

-1

如果未设置,$select_sport则未定义变量。$_POST['sport']

要修复您的代码,请在开头包含此行:

$select_sport = '';

于 2013-04-16T09:09:51.537 回答