2013-06-19 448 views
0

我的PHP代碼未定義指數:狀態

<?php 

include "conn.php"; 

if(isset($_POST['submit'])){ 

$id_guru=htmlentities($_POST['id_guru']); 
$id_pelajaran=htmlentities($_POST['id_pelajaran']); 
$id_kelas=htmlentities($_POST['id_kelas']); 

$query=mysql_query("insert into tbl_jadwal values('','$id_guru','$id_pelajaran','$id_kelas')"); 

if($query){ 
    ?><script language="javascript">document.location.href="?page=jadwal_pengajaran&status=1";</script><?php 
}else{ 
    ?><script language="javascript">document.location.href="?page=jadwal_pengajaran&status=2";</script><?php 
} 


}else{ 
unset($_POST['submit']); 
} 


?> 

<!-- start page-heading --><title>Sistem Informasi SMP YPPI</title> 
<div id="page-heading"> 
<h1>Jadwal Pengajaran</h1> 
</div> 
<!-- end page-heading --> 

<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table"> 
<tr> 
<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th> 
<th class="topleft"></th> 
<td id="tbl-border-top">&nbsp;</td> 
<th class="topright"></th> 
<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th> 
</tr> 
<tr> 
<td id="tbl-border-left"></td> 
<td> 
<!-- start content-table-inner ...................................................................... START --> 
<div id="content-table-inner"> 

     <?php 
     if(isset($_GET['status']=='1')){ 
     ?> 

     <div id="message-green"> 
     <table border="0" width="100%" cellpadding="0" cellspacing="0"> 
     <tr> 
      <td class="green-left">Data Tersimpan</td> 
      <td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td> 
     </tr> 
     </table> 
     </div> 

     <?php 
     } 

     if(isset($_GET['status']=='0')){ 
     ?> 

     <div id="message-red"> 
     <table border="0" width="100%" cellpadding="0" cellspacing="0"> 
     <tr> 
      <td class="red-left">Gagal Menyimpan</td> 
      <td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif" alt="" /></a></td> 
     </tr> 
     </table> 
     </div> 

     <?php 
     } 
     ?> 

     <form action="?page=jadwal_pengajaran" method="post"> 
     <table border="0" width="100%" cellpadding="0" cellspacing="0"> 
     <tr valign="top"> 
      <td><!-- start step-holder --> 
      <!-- end step-holder --> 
       <!-- start id-form --> 
       <table border="0" cellpadding="0" cellspacing="0" id="id-form"> 
       <tr> 
        <th valign="top">Guru</th> 
        <td><select name="id_guru" class="styledselect_form_1"> 

        <?php 
        $guru=mysql_query("select * from data_guru order by nama_guru asc"); 
        while($row1=mysql_fetch_array($guru)){ 
        ?> 
         <option value="<?php echo $row1['id_guru'];?>"><?php echo $row1['nama_guru'];?> [ <?php echo $row1['nip'];?> ]        <option> 
        <?php 
        } 
        ?>       

        </select> 
        </td> 
        <td></td> 
       </tr> 

       <tr> 
        <th valign="top">Pelajaran</th> 
        <td><select name="id_pelajaran" class="styledselect_form_1"> 

         <?php 
         $pelajaran=mysql_query("select * from setup_pelajaran order by nama_pelajaran asc"); 
         while($row2=mysql_fetch_array($pelajaran)){ 
         ?> 
          <option value="<?php echo $row2['id_pelajaran'];?>"><?php echo $row2['nama_pelajaran'];?></option> 
         <?php 
         } 
         ?>  

        </select> 
        </td> 
        <td></td> 
       </tr> 

       <tr> 
        <th valign="top">Kelas</th> 
        <td><select name="id_kelas" class="styledselect_form_1"> 

         <?php 
         $kelas=mysql_query("select * from setup_kelas order by nama_kelas asc"); 
         while($row3=mysql_fetch_array($kelas)){ 
         ?> 
          <option value="<?php echo $row3['id_kelas'];?>"><?php echo $row3['nama_kelas'];?></option> 
         <?php 
         } 
         ?>  

        </select> 
        </td> 
        <td></td> 
       </tr> 

       <tr> 
        <th>&nbsp;</th> 
        <td valign="top"><input type="submit" name="submit" class="form-submit" /> 
         <input type="reset" class="form-reset" /> 
        </td> 
        <td></td> 
       </tr> 
       </table> 
      <!-- end id-form --> 
      </td> 
      <td><!-- start related-activities --> 
      </td> 
     </tr> 
     <tr> 
      <td><img src="images/shared/blank.gif" width="695" height="1" alt="blank" /></td> 
      <td></td> 
     </tr> 
     </table> 
     </form> 

     <p><em>*Tidak boleh 1 Kelas, 1 Pelajaran di ajarkan oleh 2 Guru atau lebih<br /></em> </p>   
     <p>&nbsp;</p> 
      <!-- start product-table ..................................................................................... --> 
    <form id="mainform" action=""> 
    <table border="0" width="71%" cellpadding="0" cellspacing="0" id="product-table"> 
    <tr> 
     <th width="13%" class="table-header-repeat line-left minwidth-1"><a href="">Nomor</a> </th> 
     <th width="24%" class="table-header-repeat line-left minwidth-1"><a href="">Nama Guru</a></th> 
     <th width="26%" class="table-header-repeat line-left minwidth-1"><a href="">NIP</a></th> 
     <th width="24%" class="table-header-repeat line-left minwidth-1"><a href="">Mata Pelajaran</a></th> 
     <th width="24%" class="table-header-repeat line-left minwidth-1"><a href="">Kelas</a></th> 
     <th width="13%" class="table-header-options line-left"><a href="">Aksi</a></th> 
    </tr> 


    <?php 
    $view=mysql_query("select * from tbl_jadwal jadwal, setup_kelas kelas, setup_pelajaran pelajaran, data_guru guru where jadwal.id_kelas=kelas.id_kelas and jadwal.id_pelajaran=pelajaran.id_pelajaran and jadwal.id_guru=guru.id_guru order by id_jadwal asc"); 

    $no=0; 
    while($row=mysql_fetch_array($view)){ 
    ?> 
    <tr> 
     <td><?php echo $no=$no+1;?></td> 
     <td><?php echo $row['nama_guru'];?></td> 
     <td><?php echo $row['nip'];?></td> 
     <td><?php echo $row['nama_pelajaran'];?></td> 
     <td><?php echo $row['nama_kelas'];?></td> 
     <td class="options-width"> 
     <a href="" title="Delete" class="icon-2 info-tooltip"></a> 
     <a href="" title="Edit" class="icon-5 info-tooltip"></a>    
     </td> 
    </tr> 
    <?php 
    } 
    ?> 
    </table> 
    <!-- end product-table................................... --> 
    </form> 



<div class="clear"></div> 

</div> 
<!-- end content-table-inner ............................................END --> 
</td> 
<td id="tbl-border-right"></td> 
</tr> 
<tr> 
<th class="sized bottomleft"></th> 
<td id="tbl-border-bottom">&nbsp;</td> 
<th class="sized bottomright"></th> 
</tr> 
</table> 

警告是:

公告:未定義的索引:在C:\xampp\htdocs\tugasakhir\jadwal_pengajaran.php on line 48

通知狀態:未定義指數:狀態在C:\xampp\htdocs\tugasakhir\jadwal_pengajaran.php on line 63

我有試圖在$ get之前放置isset,但在那裏,顯示另一個警告

解析錯誤:syntax error, unexpected '==' (T_IS_EQUAL), expecting ',' or ')' in C:\xampp\htdocs\tugasakhir\jadwal_pengajaran.php on line 48

請幫我找到問題。看到

+0

您的表單在代碼段中不完整。你可以發佈其他的東西嗎? – 2013-06-19 03:55:17

+0

好的。你在那裏,我發佈了整個代碼。 –

回答

1

檢查如果你正在尋找的特定索引設置(不只是如果$_GET設置):

if(isset($_GET['status']) && '1' == $_GET['status']) { 
    // status == '1' 
} 
+0

警告消失了,但現在顯示的過程之前不應顯示的狀態。 –

+0

'if(isset($ _ GET ['status'] =='1'))'無效......你必須分開兩個if參數。 – jterry

+0

如何分開這個,先生? –

0

你可以嘗試像你的文件的頂部以下的東西

$statusExists = array_key_exists('status', $_GET); 

然後你可以輕鬆地做類似

if($status && $_GET['status'] == '1') { 
    // whatever 
} 
else if($status && $_GET['status'] == '0') { 
    // whatever else 
} 

這個問題從莖事實上,在這個處理階段「狀態」不作爲查詢字符串的一部分存在 - 所以它只是錯誤的。現在提供的代碼檢查狀態鍵是否存在,然後檢查以查看該值。

0

我沒有在您的表單中看到名稱爲status的表單元素。如果不在那裏,$_GET['status']也不存在。

isset的問題歸結爲語法錯誤 - 您以某種方式錯誤地鍵入了它。