469,365 Members | 1,789 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

Problem with this..Notice: Undefined index

Expand|Select|Wrap|Line Numbers
  1. <? ob_start();
  2. session_start();
  3. require('../includes/inc.php');
  4. require('../includes/settings.php');
  5. include("../includes/dbconnect.php");?>
  6.  
  7. <?php
  8.             // requires the class
  9.             require "../includes/class.datepicker.php";
  10.  
  11.             // instantiate the object
  12.             $db=new datepicker();
  13.  
  14.             $db->firstDayOfWeek = 1;
  15.  
  16.             // set the format in which the date to be returned
  17.             $db->dateFormat = "Y-n-j";
  18.         ?>
  19.  
  20. <link rel=stylesheet type="text/css" href="images/style.css">
  21. <body bgcolor="" bgproperties="fixed">
  22.  
  23.  
  24.  
  25. <table width="580" height="310" border="0" cellpadding="0" cellspacing="0" align="center">
  26.     <th bgcolor="#990099" align="left" valign="top" width="610" height="20"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FFFFFF"> 
  27.       MAKLUMAT KURSUS BARU</font></th>
  28.       <tr>
  29.       <td bgcolor="#CC99FF" align="right" valign="top" width="580"><br>
  30.  
  31.  
  32.   <tr>
  33.       <td bgcolor="#CC99FF" align="left" valign="top" width="580"> 
  34.  
  35.       <form name="formupdate" action="kurs_baru.php" method="post">
  36.         <br><table width="580" border="0" cellpadding="5" cellspacing="3" align="center" dwcopytype="CopyTableRow">
  37.  
  38.             <tr>
  39.               <td class="content" width="150">Nama Kursus/Latihan</td>
  40.               <td class="content" width="445" colspan="3">
  41.             <input type="text" name='kurs_name' value="" size="67">
  42.             </td>
  43.           </tr>
  44.  
  45.           <tr>
  46.               <td class="content" width="150">Tempat Kursus/Latihan</td>
  47.               <td class="content" width="445" colspan="3">
  48.             <input type="text" name='kurs_tmpt' value="" size="67">
  49.             </td>
  50.           </tr>    
  51.            <tr>
  52.             <td class="content" width="140">Jenis Kursus </td>
  53.               <td class="content" width="445" colspan="3">    
  54.                <select name="kurs_jenis">
  55.                 <option value="-" selected>Pilih</option>
  56.                 <option value="Umum">Umum</option>
  57.                 <option value="Khusus">Khusus</option>
  58.                 <option value="Teknikal/IT">Teknikal/IT</option>
  59.               </select>    
  60.             </tr>    
  61.           <tr>
  62.               <td class="content" width="150">Tarikh Mula</td>
  63.             <td class="content" width="430" colspan="3">
  64.                 <input type="text" id="date" name="kurs_frst_date" value="">
  65.                 <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">
  66.             </td>
  67.             </tr>
  68.           <tr>
  69.               <td class="content" width="150">Tarikh Tamat</td>
  70.             <td class="content" width="430" colspan="3"> 
  71.             <input type="text" id="date1" name="kurs_last_date" value=""> 
  72.               <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">
  73.             </td>
  74.             </tr>
  75.  
  76.  
  77.             <tr>
  78.               <td class="content" width="150">Penganjur</td>
  79.               <td class="content" width="445" colspan="3">
  80. <?
  81.         $querypenganjur = "SELECT * FROM penganjur ORDER BY anjur_name";        
  82.         $resultpenganjur = mysql_query($querypenganjur) or die (mysql_error());
  83. ?>            
  84.           <select name="anjur_name">
  85.                 <option value="-" selected>Pilih</option>
  86.             <? while($view2 = mysql_fetch_array($resultpenganjur)){?>
  87.                 <option value="<? echo $view2['anjur_id'];?>"><? echo $view2['anjur_name'];?></option>
  88.             <?     }?>
  89.                 </select>    
  90.             </tr>    
  91.  
  92.  
  93.  
  94.           <tr>
  95.             <td class="content" width="150"></td>
  96.             <td class="content" width="445" colspan="3">
  97.                 <input type="submit" name="Submit" value="Daftar">
  98.             </td>
  99.           </tr>
  100.  
  101.           </table><!-- end table form -->
  102.  
  103.  
  104.  
  105. </form>
  106.     <? if($_POST['Submit'] == "Daftar") { //submit info
  107.  
  108.  
  109.             $kurs_name            =    $_POST['kurs_name'];
  110.             $kurs_tmpt            =    $_POST['kurs_tmpt'];
  111.             $kurs_jenis            =    $_POST['kurs_jenis'];
  112.             $kurs_frst_date        =    $_POST['kurs_frst_date'];
  113.             $kurs_last_date        =    $_POST['kurs_last_date'];
  114.             $anjur_name            =    $_POST['anjur_name'];
  115.  
  116.             $add_staf="INSERT INTO kursus VALUES ('', '$kurs_name', '$kurs_tmpt', '$kurs_jenis', '$kurs_frst_date', '$kurs_last_date', '', '', '', 
  117.                             '$anjur_name')";            
  118.             $result_add = mysql_query($add_staf) or die (mysql_error());
  119.  
  120.             $querykur = "SELECT * FROM kursus ORDER BY kurs_id DESC limit 1";
  121.             $resultkur = mysql_query($querykur) or die (mysql_error());
  122.             $viewkur = mysql_fetch_array($resultkur);
  123.  
  124.             $kurs_id = $viewkur['kurs_id'];
  125.  
  126.             $add_kurs="INSERT INTO sk VALUES ('', '$s_id', '$kurs_id')";            
  127.             $result_kurs = mysql_query($add_kurs) or die (mysql_error());
  128.  
  129.  
  130.     ?>
  131.     <br><table width="580" border="0" cellpadding="5" cellspacing="3" align="center">
  132.            <tr>
  133.               <td bgcolor="" colspan="4" class="content" width="595">
  134.             <B>MAKLUMAT KURSUS TELAH DIDAFTAR.</B><br><br>
  135.             </td>
  136.           </tr>
  137.           <tr>    
  138.           <td class="content" width="150" bgcolor="#FFCC00">Nama Kursus/Latihan</td>
  139.               <td class="content" width="445" colspan="3" bgcolor="#FFFF99">
  140.             <? echo $kurs_name;?>
  141.             </td>
  142.           </tr>     
  143.           <tr>
  144.           <td class="content" width="150" bgcolor="#FFCC00">Tempat Kursus/Latihan</td>
  145.               <td class="content" width="445" colspan="3" bgcolor="#FFFF99">
  146.             <? echo $kurs_tmpt;?>
  147.             </td>
  148.           </tr>     
  149.           <tr> 
  150.           <td class="content" width="140" valign="top" bgcolor="#FFCC00">Jenis Kursus</td>
  151.               <td class="content" width="157.5" bgcolor="#FFFF99"><? echo $kurs_jenis;?></td>
  152.           </tr> 
  153.           <tr>
  154.               <td class="content" width="150" bgcolor="#FFCC00">Tarikh Masuk</td>
  155.             <td class="content" width="147.5" bgcolor="#FFFF99">
  156.                 <? echo $kurs_frst_date;?>
  157.             </td>
  158.             <td colspan="2" width="297.5">&nbsp;</td>
  159.             </tr>
  160.         <tr>
  161.               <td class="content" width="150" bgcolor="#FFCC00">Tarikh Tamat</td>
  162.             <td class="content" width="147.5" bgcolor="#FFFF99">
  163.                 <? echo $kurs_last_date;?>
  164.             </td>
  165.             <td colspan="2" width="297.5">&nbsp;</td>
  166.             </tr>
  167.             <tr>    
  168.           <td class="content" width="150" bgcolor="#FFCC00">Penganjur</td>
  169.  
  170.           <td class="content" width="445" colspan="3" bgcolor="#FFFF99"> 
  171.             <?
  172.         $querypenganjur = "SELECT * FROM penganjur WHERE anjur_id='$anjur_name'";        
  173.         $resultpenganjur = mysql_query($querypenganjur) or die (mysql_error());
  174.         $view7 = mysql_fetch_array($resultpenganjur);
  175. ?>
  176.             <? echo $view7['anjur_name'];?> </td>
  177.           </tr>
  178.          <tr> 
  179.           <td class="content" width="595" valign="top" align="right" bgcolor="" colspan="4"> 
  180.             <b>[</b><a href="javascript:history.go(-1)" class="a">Back</a><b>]</b> 
  181.  
  182.             <br>
  183.             <br> </td>
  184.         </tr>
  185.  
  186.         </table><!-- end table form -->
  187.  
  188.      <?
  189.     }//end elseif Tambah Staf?>
  190.     </td>
  191.  </tr>
  192. </table><!-- end table background -->
  193. </body>
  194.  

i've got error message undefined index:Submit..but 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..
Sep 24 '08 #1
8 10070
Markus
6,050 Expert 4TB
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
Sep 24 '08 #2
Markus
6,050 Expert 4TB
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.
Sep 24 '08 #3
Atli
5,058 Expert 4TB
Hi.

When you check whether your data has been submitted:
Expand|Select|Wrap|Line Numbers
  1. if($_POST['Submit'] == "Daftar")
  2.  
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 "Unidentified 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.
Sep 24 '08 #4
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.
Sep 24 '08 #5
Markus
6,050 Expert 4TB
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.
Sep 24 '08 #6
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\VertrigoServ\www\elatihan\admin\kurs_baru.ph p on line 98

tq for the replying to all..
Sep 25 '08 #7
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..
Sep 25 '08 #8
Markus
6,050 Expert 4TB
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.

Expand|Select|Wrap|Line Numbers
  1. if ( @$_POST['Submit'] == 'Something' )
  2.  
Sep 25 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by Joe Blow | last post: by
5 posts views Thread by Pseudonyme | last post: by
22 posts views Thread by V S Rawat | last post: by
chelvan
5 posts views Thread by chelvan | last post: by
2 posts views Thread by Smellydog | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.