Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

php - Option Menu Showing Undefined Index

Have an option menu that is driving me crazy.

<?PHP 
$text=($_POST['selGrade']);
echo (!empty($text) ? $text : "ALL");
?>

The menu is fed by a table that is set to % to show all records on page load. On load the page shows "Notice: Undefined index: selGrade in..." Selecting an option will echo correctly. Selecting All records from the option Menu will echo "%".

Here is my option menu:

<form id="formGrade" name="formGrade" method="post" action="#Grade">
  Filter  by grade level: <strong>
  <select name="selGrade" id="selGrade"  
  onchange="formGrade.submit()">
  <option value="%">all grade levels</option>
  <?php
  do {  
   ?>
   <option value="<?php echo $row_RecordsetGrade['Grade']?>"<?php

    if ($varGrade_Recordset15 == $row_RecordsetGrade['Grade']) {echo 'selected';} ?>>
    <?php echo $row_RecordsetGrade['Grade']?></option>
    <?php
  } while ($row_RecordsetGrade = mysql_fetch_assoc($RecordsetGrade));
  $rows = mysql_num_rows($RecordsetGrade);
  if($rows > 0) {
    mysql_data_seek($RecordsetGrade, 0);
    $row_RecordsetGrade = mysql_fetch_assoc($RecordsetGrade);
  }
  ?>
</select>
</strong><a href="course_types.php">reset</a>
</form>

I just want it to echo the option menu selected. All grades (which is the default should echo "ALL" and everything else seems to be working fine. Problem seems to be the onload and when selecting All Records again. Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this change in your code

 if(!isset($_POST['selGrade']) || empty($_POST['selGrade']) || $_POST['selGrade']=="%"){
    $text = "ALL";
    } else {
    $text = $_POST['selGrade'];
    }
    echo $text;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...