Problem with this..Notice: Undefined index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaielinna
    New Member
    • Sep 2008
    • 3

    #1

    Problem with this..Notice: Undefined index

    Code:
    <? ob_start();
    session_start();
    require('../includes/inc.php');
    require('../includes/settings.php');
    include("../includes/dbconnect.php");?>
    
    <?php
    			// requires the class
    			require "../includes/class.datepicker.php";
    					
    			// instantiate the object
    			$db=new datepicker();
    					
    			$db->firstDayOfWeek = 1;
    				
    			// set the format in which the date to be returned
    			$db->dateFormat = "Y-n-j";
    		?>
    
    <link rel=stylesheet type="text/css" href="images/style.css">
    <body bgcolor="" bgproperties="fixed">
    
    
    
    <table width="580" height="310" border="0" cellpadding="0" cellspacing="0" align="center">
        <th bgcolor="#990099" align="left" valign="top" width="610" height="20"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FFFFFF"> 
          MAKLUMAT KURSUS BARU</font></th>
    	  <tr>
      	<td bgcolor="#CC99FF" align="right" valign="top" width="580"><br>
    	
    
      <tr>
      	<td bgcolor="#CC99FF" align="left" valign="top" width="580"> 
         
          <form name="formupdate" action="kurs_baru.php" method="post">
    		<br><table width="580" border="0" cellpadding="5" cellspacing="3" align="center" dwcopytype="CopyTableRow">
    		
    			<tr>
    		  	<td class="content" width="150">Nama Kursus/Latihan</td>
    		  	<td class="content" width="445" colspan="3">
    			<input type="text" name='kurs_name' value="" size="67">
    			</td>
    		  </tr>
    		 
    		  <tr>
    		  	<td class="content" width="150">Tempat Kursus/Latihan</td>
    		  	<td class="content" width="445" colspan="3">
    			<input type="text" name='kurs_tmpt' value="" size="67">
    			</td>
    		  </tr>	
    		   <tr>
    		    <td class="content" width="140">Jenis Kursus </td>
    		  	<td class="content" width="445" colspan="3">	
    		  	 <select name="kurs_jenis">
                    <option value="-" selected>Pilih</option>
                    <option value="Umum">Umum</option>
                    <option value="Khusus">Khusus</option>
                    <option value="Teknikal/IT">Teknikal/IT</option>
                  </select>	
    			</tr>    
    		  <tr>
    		  	<td class="content" width="150">Tarikh Mula</td>
    			<td class="content" width="430" colspan="3">
    				<input type="text" id="date" name="kurs_frst_date" value="">
    				<input type="button" value="Pilih Tarikh" onClick="javascript:var cw = null; cw = window.open('../includes/includes/datepicker.php?preselectedDate=&month=&year=&controlName=date&dateFormat=Y-n-j&firstDayOfWeek=1&clearDateButton=1&language=english&template=default','datePicker','width=200,height=210,scrollbars=no,toolbar=no,menubar=no,location=no,alwaysraised=yes,modal=yes'); if (window.focus) { cw.focus() } return true">
    			</td>
    			</tr>
    		  <tr>
    		  	<td class="content" width="150">Tarikh Tamat</td>
    			<td class="content" width="430" colspan="3"> 
    			<input type="text" id="date1" name="kurs_last_date" value=""> 
                  <input type="button" value="Pilih Tarikh" onClick="javascript:var cw = null; cw = window.open('../includes/includes/datepicker.php?preselectedDate=&month=&year=&controlName=date1&dateFormat=Y-n-j&firstDayOfWeek=1&clearDateButton=1&language=english&template=default','datePicker','width=200,height=210,scrollbars=no,toolbar=no,menubar=no,location=no,alwaysraised=yes,modal=yes'); if (window.focus) { cw.focus() } return true">
    			</td>
    			</tr>
    		
      		  
      		  <tr>
    		  	<td class="content" width="150">Penganjur</td>
    		  	<td class="content" width="445" colspan="3">
    <?
    		$querypenganjur = "SELECT * FROM penganjur ORDER BY anjur_name";		
    		$resultpenganjur = mysql_query($querypenganjur) or die (mysql_error());
    ?>			
    		  <select name="anjur_name">
                    <option value="-" selected>Pilih</option>
    			<? while($view2 = mysql_fetch_array($resultpenganjur)){?>
                    <option value="<? echo $view2['anjur_id'];?>"><? echo $view2['anjur_name'];?></option>
    			<? 	}?>
                    </select>	
    			</tr>    
    		  		  
    		
    		  
    		  <tr>
    			<td class="content" width="150"></td>
    			<td class="content" width="445" colspan="3">
    				<input type="submit" name="Submit" value="Daftar">
    			</td>
    		  </tr>
    		 
    		  </table><!-- end table form -->
    		  
    	 
    
    </form>
    	<? if($_POST['Submit'] == "Daftar") { //submit info
    	
    			
    			$kurs_name			=	$_POST['kurs_name'];
    			$kurs_tmpt			=	$_POST['kurs_tmpt'];
    			$kurs_jenis			=	$_POST['kurs_jenis'];
    			$kurs_frst_date		=	$_POST['kurs_frst_date'];
    			$kurs_last_date		=	$_POST['kurs_last_date'];
    			$anjur_name			=	$_POST['anjur_name'];
    			
    			$add_staf="INSERT INTO kursus VALUES ('', '$kurs_name', '$kurs_tmpt', '$kurs_jenis', '$kurs_frst_date', '$kurs_last_date', '', '', '', 
    							'$anjur_name')";			
    			$result_add = mysql_query($add_staf) or die (mysql_error());
    			
    			$querykur = "SELECT * FROM kursus ORDER BY kurs_id DESC limit 1";
    			$resultkur = mysql_query($querykur) or die (mysql_error());
    			$viewkur = mysql_fetch_array($resultkur);
    			
    			$kurs_id = $viewkur['kurs_id'];
    			
    			$add_kurs="INSERT INTO sk VALUES ('', '$s_id', '$kurs_id')";			
    			$result_kurs = mysql_query($add_kurs) or die (mysql_error());
    
    
    	?>
    	<br><table width="580" border="0" cellpadding="5" cellspacing="3" align="center">
    		   <tr>
    		  	<td bgcolor="" colspan="4" class="content" width="595">
    			<B>MAKLUMAT KURSUS TELAH DIDAFTAR.</B><br><br>
    			</td>
    		  </tr>
    		  <tr>	
              <td class="content" width="150" bgcolor="#FFCC00">Nama Kursus/Latihan</td>
    		  	<td class="content" width="445" colspan="3" bgcolor="#FFFF99">
    			<? echo $kurs_name;?>
    			</td>
    		  </tr>	 
    		  <tr>
    		  <td class="content" width="150" bgcolor="#FFCC00">Tempat Kursus/Latihan</td>
    		  	<td class="content" width="445" colspan="3" bgcolor="#FFFF99">
    			<? echo $kurs_tmpt;?>
    			</td>
    		  </tr>	 
    		  <tr> 
    		  <td class="content" width="140" valign="top" bgcolor="#FFCC00">Jenis Kursus</td>
    		  	<td class="content" width="157.5" bgcolor="#FFFF99"><? echo $kurs_jenis;?></td>
    		  </tr> 
    		  <tr>
    		  	<td class="content" width="150" bgcolor="#FFCC00">Tarikh Masuk</td>
    			<td class="content" width="147.5" bgcolor="#FFFF99">
    				<? echo $kurs_frst_date;?>
    			</td>
    			<td colspan="2" width="297.5">&nbsp;</td>
    			</tr>
    		<tr>
    		  	<td class="content" width="150" bgcolor="#FFCC00">Tarikh Tamat</td>
    			<td class="content" width="147.5" bgcolor="#FFFF99">
    				<? echo $kurs_last_date;?>
    			</td>
    			<td colspan="2" width="297.5">&nbsp;</td>
    			</tr>
      		  <tr>	
              <td class="content" width="150" bgcolor="#FFCC00">Penganjur</td>
    		  	
              <td class="content" width="445" colspan="3" bgcolor="#FFFF99"> 
                <?
    		$querypenganjur = "SELECT * FROM penganjur WHERE anjur_id='$anjur_name'";		
    		$resultpenganjur = mysql_query($querypenganjur) or die (mysql_error());
    		$view7 = mysql_fetch_array($resultpenganjur);
    ?>
                <? echo $view7['anjur_name'];?> </td>
    		  </tr>
    		 <tr> 
              <td class="content" width="595" valign="top" align="right" bgcolor="" colspan="4"> 
                <b>[</b><a href="javascript:history.go(-1)" class="a">Back</a><b>]</b> 
                
                <br>
                <br> </td>
            </tr>
    		  		  
    		</table><!-- end table form -->
    
    	 <?
    	}//end elseif Tambah Staf?>
    	</td>
     </tr>
    </table><!-- end table background -->
    </body>

    i've got error message undefined index:Submit..b ut i still kt insert data in that form and when i submit,the data will save in table in database.but the error msg appear..so i dont get it..
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Welcome to the forums, Shai.

    When posting code in the forums, you are to post them wrapped in code tags. Example: [code] code goes here ... [/code]. Please follow these rules as outline in the posting guidelines (which you are expected to have read already.)

    Moderator

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      When you receive the said error, you are given a line number corresponding to the error. What is the line number? Help us help you.

      Cheers.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        When you check whether your data has been submitted:
        [code=php]
        if($_POST['Submit'] == "Daftar")
        [/code]
        If it has been submitted, this will work fine, but when it hasn't been submitted the $_POST array won't contain an element named 'Submit'.
        Which will produce a "Unidentifi ed index" warning.

        In your script it doesn't actually matter, because either way the if statement will evaluate FALSE, but to get rid of the warning, try checking if the index is set first using the isset function.

        Comment

        • gabosom
          New Member
          • Sep 2008
          • 9

          #5
          You can also try using the '@' before the statement so the warning doesn't show up =). But I would too use the isset function first.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by gabosom
            You can also try using the '@' before the statement so the warning doesn't show up =). But I would too use the isset function first.
            True, but bad programming. It's like women covering up their blemishes; it may look good on the night out, but that ugly programming will show in the morning.

            Cheers,
            Mark.

            Comment

            • shaielinna
              New Member
              • Sep 2008
              • 3

              #7
              ok..i still new..n i will follow guideline after this...
              erm the error show in line 98..
              this program will have form..n i still can use the form..but there was error msg at the bottom..

              Notice: Undefined index: Submit in C:\Program Files\VertrigoS erv\www\elatiha n\admin\kurs_ba ru.php on line 98

              tq for the replying to all..

              Comment

              • shaielinna
                New Member
                • Sep 2008
                • 3

                #8
                when i done this..it still running..the data that i post is save in the table on database..it just about the error msg appear at the bottom of the form..

                tq for others tht reply n help me..

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  You get this error because PHP is checking for a $_POST['Submit'] when the form may not have been sent, therefore, the array will be empty.

                  As mentioned previously, you can append an @ symbol to surpress the error.

                  [code=php]
                  if ( @$_POST['Submit'] == 'Something' )
                  [/code]

                  Comment

                  Working...