Error in Internet-explorer when retrieving data from mysql database (but works in firefox)

I wrote the following form in the showList.php file that selects items from the database and displays them in the drop-down list:

<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>

I include this file in index.php as follows:

<?php include('showList.php');?>

Now, when I call index.php, the list of expandable forms will be displayed in the drop-down list.

This works fine in firefox, my problem is when I call index.php in internetexplorer, I get the following error:

Notice: Undefined index: selection in C:\path\showList.php on line 43

Line 43:

if($_POST['selection']==$selection_id)$selElement="selected";

as you can see in the above form. Any idea?

+5
source share
2 answers

You need to change the problem line:

if($_POST['selection']==$selection_id)$selElement="selected";

at

if(isset($_POST['selection']) && ($_POST['selection']==$selection_id))
    $selElement="selected";

to check what the value is for (as suggested by @ b1onic).

, POSTed - , , - .

+2

, php script "" $_POST, .

:

if($_POST['selection']==$selection_id)

:

if(array_key_exists('selection', $_POST) && $_POST['selection'] == $selection_id)

if(isset($_POST['selection']) && $_POST['selection'] == $selection_id) 

array_key_exists. isset(), .

+2

All Articles