2013-06-19 244 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的问题归结为语法错误 - 您以某种方式错误地键入了它。