【发布时间】:2013-04-16 05:35:57
【问题描述】:
<?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>
当我在浏览器上打开这个程序时,错误“未定义索引”出现在 SELECT 选项(下拉框)中。,
但是当我单击保存按钮时,错误消失了。当我不选择任何运动时,它工作正常,它显示错误消息。
所以请帮我找到解决方案...
【问题讨论】:
-
在这里粘贴你的整个代码,stackoverflow 有最好的编辑器(用户),他们会让你的代码可读
-
您的选项关闭标签在哪里?还有你的选择关闭标签在哪里?如果 if (isset($_POST['save'])) 的计算结果不为真,则变量 $select_sport 也不会被设置。当您尝试访问不存在的数组索引时会发生未定义的索引错误,因此可能是 $_POST 索引之一。从您发布的代码中很难说。
标签: php select indexing undefined option