从mysql数据库检索数据时Internet-explorer出错(但在firefox中有效)

Max*_*lah 5 html php mysql internet-explorer

我在文件showList.php中写了以下表格,它从数据库中选择项目并在下拉列表中显示:

<form id="selForm" name="selForm" action="index.php" method="post">
<select name="selection" id="selection">
<option id="nothingSelected" >--Choose form---></option>
<?php

$con=mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("myDatabase",$con);
$result = mysql_query("SELECT * FROM formsTable");

while($row = mysql_fetch_array($result))
  {
  $selection_id=$row['id'];
if($_POST['selection']==$selection_id)$selElement="selected";
  echo "<option  id='$selection_id' name=\"sectionid\"  value='$selection_id' >";
  echo $row['nummer'] . " " . $row['titel']. " ";
  echo "</option>";
  }
?>

</select>
<input type="button" value="load form" onClick="validateForm(document.selForm)">
<input type="button" value="delete form" onClick="deleteForm(document.selForm);">
</form>
Run Code Online (Sandbox Code Playgroud)

我将此文件包含在index.php中,如下所示:

<?php include('showList.php');?>
Run Code Online (Sandbox Code Playgroud)

现在,当我调用index.php时,找到的表单列表将显示在下拉列表中.

这在firefox中运行正常,我的问题是当我在internetexplorer中调用index.php时,我收到以下错误:

Notice: Undefined index: selection in C:\path\showList.php on line 43
Run Code Online (Sandbox Code Playgroud)

第43行是:

if($_POST['selection']==$selection_id)$selElement="selected";
Run Code Online (Sandbox Code Playgroud)

正如您在上面的表格中看到的那样.任何的想法?

Ann*_*bel 2

您需要将问题行从:

if($_POST['selection']==$selection_id)$selElement="selected";
Run Code Online (Sandbox Code Playgroud)

到:

if(isset($_POST['selection']) && ($_POST['selection']==$selection_id))
    $selElement="selected";
Run Code Online (Sandbox Code Playgroud)

检查值(如 @b1onic 建议)。

显然,第一次在浏览器中显示表单时不会发布任何内容 - 无论您使用哪种浏览器 - 因此您都会收到该错误。