How to fix undefined index error in in line no3

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kanika
    New Member
    • Sep 2012
    • 1

    How to fix undefined index error in in line no3

    Code:
    <?php
    
    $iit1=$_POST['iit1'];
    $iit2=$_POST['iit2'];
    $iit3=$_POST['iit3'];
    $iit4=$_POST['iit4'];
    $iit5=$_POST['iit5'];
    $iit6=$_POST['iit6'];
    $iit7=$_POST['iit7'];
    $iit8=$_POST['iit8'];
    $iit9=$_POST['iit9'];
    $iit10=$_POST['iit10'];
    
    $c1=$_POST['c1'];
    $c2=$_POST['c2'];
    $c3=$_POST['c3'];
    $c4=$_POST['c4'];
    $c5=$_POST['c5'];
    $c6=$_POST['c6'];
    $c7=$_POST['c7'];
    $c8=$_POST['c8'];
    $c9=$_POST['c9'];
    $c10=$_POST['c10'];
    
    $te1=$_POST['te1'];
    $te2=$_POST['te2'];
    $te3=$_POST['te3'];
    $te4=$_POST['te4'];
    $te5=$_POST['te5'];
    $te6=$_POST['te6'];
    $te7=$_POST['te7'];
    $te8=$_POST['te8'];
    $te9=$_POST['te9'];
    $te10=$_POST['te10'];
    
    $ai1=$_POST['ai1'];
    $ai2=$_POST['ai2'];
    $ai3=$_POST['ai3'];
    $ai4=$_POST['ai4'];
    $ai5=$_POST['ai5'];
    $ai6=$_POST['ai6'];
    $ai7=$_POST['ai7'];
    $ai8=$_POST['ai8'];
    $ai9=$_POST['ai9'];
    $ai10=$_POST['ai10'];
    
    $cn21=$_POST['cn21'];
    $cn22=$_POST['cn22'];
    $cn23=$_POST['cn23'];
    $cn24=$_POST['cn24'];
    $cn25=$_POST['cn25'];
    $cn26=$_POST['cn26'];
    $cn27=$_POST['cn27'];
    $cn28=$_POST['cn28'];
    $cn29=$_POST['cn29'];
    $cn210=$_POST['cn210'];
    
    $mf1=$_POST['mf1'];
    $mf2=$_POST['mf2'];
    $mf3=$_POST['mf3'];
    $mf4=$_POST['mf4'];
    $mf5=$_POST['mf5'];
    $mf6=$_POST['mf6'];
    $mf7=$_POST['mf7'];
    $mf8=$_POST['mf8'];
    $mf9=$_POST['mf9'];
    $mf10=$_POST['mf10'];
    
    $co1=$_POST['co1'];
    $co2=$_POST['co2'];
    $co3=$_POST['co3'];
    $co4=$_POST['co4'];
    $co5=$_POST['co5'];
    $co6=$_POST['co6'];
    $co7=$_POST['co7'];
    $co8=$_POST['co8'];
    $co9=$_POST['co9'];
    $co10=$_POST['co10'];
    
    $ps1=$_POST['ps1'];
    $ps2=$_POST['ps2'];
    $ps3=$_POST['ps3'];
    $ps4=$_POST['ps4'];
    $ps5=$_POST['ps5'];
    $ps6=$_POST['ps6'];
    $ps7=$_POST['ps7'];
    $ps8=$_POST['ps8'];
    $ps9=$_POST['ps9'];
    $ps10=$_POST['ps10'];
    
    $dms1=$_POST['dms1'];
    $dms2=$_POST['dms2'];
    $dms3=$_POST['dms3'];
    $dms4=$_POST['dms4'];
    $dms5=$_POST['dms5'];
    $dms6=$_POST['dms6'];
    $dms7=$_POST['dms7'];
    $dms8=$_POST['dms8'];
    $dms9=$_POST['dms9'];
    $dms10=$_POST['dms10'];
    
    $ds1=$_POST['ds1'];
    $ds2=$_POST['ds2'];
    $ds3=$_POST['ds3'];
    $ds4=$_POST['ds4'];
    $ds5=$_POST['ds5'];
    $ds6=$_POST['ds6'];
    $ds7=$_POST['ds7'];
    $ds8=$_POST['ds8'];
    $ds9=$_POST['ds9'];
    $ds10=$_POST['ds10'];
    
    $u1=$_POST['u1'];
    $u2=$_POST['u2'];
    $u3=$_POST['u3'];
    $u4=$_POST['u4'];
    $u5=$_POST['u5'];
    $u6=$_POST['u6'];
    $u7=$_POST['u7'];
    $u8=$_POST['u8'];
    $u9=$_POST['u9'];
    $u10=$_POST['u10'];
    
    $cg1=$_POST['cg1'];
    $cg2=$_POST['cg2'];
    $cg3=$_POST['cg3'];
    $cg4=$_POST['cg4'];
    $cg5=$_POST['cg5'];
    $cg6=$_POST['cg6'];
    $cg7=$_POST['cg7'];
    $cg8=$_POST['cg8'];
    $cg9=$_POST['cg9'];
    $cg10=$_POST['cg10'];
    
    
    $bc1=$_POST['bc1'];
    $bc2=$_POST['bc2'];
    $bc3=$_POST['bc3'];
    $bc4=$_POST['bc4'];
    $bc5=$_POST['bc5'];
    $bc6=$_POST['bc6'];
    $bc7=$_POST['bc7'];
    $bc8=$_POST['bc8'];
    $bc9=$_POST['bc9'];
    $bc10=$_POST['bc10'];
    
    $se1=$_POST['se1'];
    $se2=$_POST['se2'];
    $se3=$_POST['se3'];
    $se4=$_POST['se4'];
    $se5=$_POST['se5'];
    $se6=$_POST['se6'];
    $se7=$_POST['se7'];
    $se8=$_POST['se8'];
    $se9=$_POST['se9'];
    $se10=$_POST['se10'];
    
    
    $ss1=$_POST['ss1'];
    $ss2=$_POST['ss2'];
    $ss3=$_POST['ss3'];
    $ss4=$_POST['ss4'];
    $ss5=$_POST['ss5'];
    $ss6=$_POST['ss6'];
    $ss7=$_POST['ss7'];
    $ss8=$_POST['ss8'];
    $ss9=$_POST['ss9'];
    $ss10=$_POST['ss10'];
    
    $d1=$_POST['d1'];
    $d2=$_POST['d2'];
    $d3=$_POST['d3'];
    $d4=$_POST['d4'];
    $d5=$_POST['d5'];
    $d6=$_POST['d6'];
    $d7=$_POST['d7'];
    $d8=$_POST['d8'];
    $d9=$_POST['d9'];
    $d10=$_POST['d10'];
    
    $sad1=$_POST['sad1'];
    $sad2=$_POST['sad2'];
    $sad3=$_POST['sad3'];
    $sad4=$_POST['sad4'];
    $sad5=$_POST['sad5'];
    $sad6=$_POST['sad6'];
    $sad7=$_POST['sad7'];
    $sad8=$_POST['sad8'];
    $sad9=$_POST['sad9'];
    $sad10=$_POST['sad10'];
    
    
    
    $j1=$_POST['j1'];
    $j2=$_POST['j2'];
    $j3=$_POST['j3'];
    $j4=$_POST['j4'];
    $j5=$_POST['j5'];
    $j6=$_POST['j6'];
    $j7=$_POST['j7'];
    $j8=$_POST['j8'];
    $j9=$_POST['j9'];
    $j10=$_POST['j10'];
    
    
    $ada1=$_POST['ada1'];
    $ada2=$_POST['ada2'];
    $ada3=$_POST['ada3'];
    $ada4=$_POST['ada4'];
    $ada5=$_POST['ada5'];
    $ada6=$_POST['ada6'];
    $ada7=$_POST['ada7'];
    $ada8=$_POST['ada8'];
    $ada9=$_POST['ada9'];
    $ada10=$_POST['ada10'];
    
    $cn1=$_POST['cn1'];
    $cn2=$_POST['cn2'];
    $cn3=$_POST['cn3'];
    $cn4=$_POST['cn4'];
    $cn5=$_POST['cn5'];
    $cn6=$_POST['cn6'];
    $cn7=$_POST['cn7'];
    $cn8=$_POST['cn8'];
    $cn9=$_POST['cn9'];
    $cn10=$_POST['cn10'];
    
    $sim1=$_POST['sim1'];
    $sim2=$_POST['sim2'];
    $sim3=$_POST['sim3'];
    $sim4=$_POST['sim4'];
    $sim5=$_POST['sim5'];
    $sim6=$_POST['sim6'];
    $sim7=$_POST['sim7'];
    $sim8=$_POST['sim8'];
    $sim9=$_POST['sim9'];
    $sim10=$_POST['sim10'];
    
    ?>
    Last edited by Niheel; Sep 10 '12, 08:58 AM. Reason: that's a lot of code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    An undefined index error means that they key you're using, in this case 'iit1' doesn't exist in the array you're trying to access, in this case $_POST. Basically, it's saying the page that called that PHP page didn't pass any variable named iit1.

    Comment

    • ayukawaa
      New Member
      • Sep 2012
      • 9

      #3
      Here's my own function for dealing with this... and works with ANY array

      $iit1=read_from _array[$_POST, 'iit1'];

      Code:
      /*
       * READ A VALUE FROM AN ARRAY
       * param array - array from where to read
       * param string - key to read from the array
       * param string - default_value to return if the key does not exist or the it is not a valid array
       * param php_function - php function to execute using the key value
       * return string
       *
      **/
      	function read_from_array($array, $key, $default_value='', $php_function='')
      	{
      		if(is_array($array))
      		{
      			if (array_key_exists($key, $array))
      			{
      				$str = str_replace('\\', '/', trim($array[$key]));
      				if(!empty($php_function))
      				{
      					return call_user_func($php_function, $str);
      				}
      				else
      				{
      					return $str;
      				}
      			}
      		}
      		return $default_value;
      	}
      }

      Comment

      Working...