PHP Error: Undefined index: event_list when I think its already defined. -


i complete noob in php , programming well. new programming question might stupid, please patient.

i having undefined index error in think defined.

i have here codes.

index.php

<?php include('functions.php'); ?>  <?php   $yr = $_get['year_list'];  $evnt = $_get['event_list'];  ?>  <html> <head>  <script type="text/javascript" src="myscripts.js"></script> </head> <body>  <div>   <form name="myform" >    select year: <?php echo hspacer(1); ?>    <select id="year_list" name="year_list">    <?php       for($year = (date('y') - 100); $year <= (date('y') + 100); $year++ ) {      if ($year == date('y'))  echo "<option value='$year' name='$year' selected='' >" . $year . "</option>";      else echo "<option value='$year' name='$year' >" . $year . "</option>";     }    ?>    </select>    <?php echo hspacer(5); ?>    select event:  <?php echo hspacer(1); ?>    <select id="event_list" name="event_list" >    <?php       $events = array("karate tournament", "beauty pageant", "film festival", "singing contest", "wedding");      foreach($events $event) echo "<option value='$event' name='$event' >" . $event . "</option>";    ?>    </select>    <?php echo vspacer(2); echo hspacer(22); ?>    <input type="submit" id="add_description" name="add_description" value="add description" onclick=""/>    </form>  </div> </body> </html> 


functions.php

<?php  function hspacer($num_of_spaces) {   $spaces = "";   if ($num_of_spaces > 0)  for($i=0; $i<$num_of_spaces; $i++ )  $spaces .= "&nbsp;";    return $spaces;  }   function vspacer($num_of_linefeeds) {   $linefeeds = "";   if ($num_of_linefeeds > 0)  for($i=0; $i<$num_of_linefeeds; $i++ )  $linefeeds .= "<br />";    return $linefeeds;  } ?> 

what don't understand this, think when declared element id can use id index $_get or $_post. secondly, why second element (event_list) not recognized when have same declaration first element (year_list). i'm confused inconsistency. second element not recognized while other first 1 recognized. can please explain me in simple way beginner me can understand.

could have &year_list allready in url, when accessing page? otherwise there no reason not same error when accessing $_get['year_list'];

and should check access _get/_post etc. instead of assuming keys set.

try:

$yr = isset($_get['year_list']) ? $_get['year_list'] : null; $evnt = isset($_get['event_list']) ? $_get['event_list'] : null;  

you build function reduce of code. have at:

http://php.net/manual/en/ref.filter.php , http://www.php.net/manual/en/ini.core.php#ini.register-globals


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -