提问人:Nico David 提问时间:6/19/2013 最后编辑:Nico David 更新时间:6/19/2013 访问量:6928
未定义的索引:状态 [已关闭]
Undefined index: status [closed]
问:
我的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"> </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> </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> </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"> </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
我试图将 isset 放在$get之前,但它就在那里,显示了另一个警告
解析错误:syntax error, unexpected '==' (T_IS_EQUAL), expecting ',' or ')' in C:\xampp\htdocs\tugasakhir\jadwal_pengajaran.php on line 48
请帮我找到问题。
答:
3赞
jterry
6/19/2013
#1
检查您要查找的特定索引是否已设置(而不仅仅是是否设置):$_GET
if(isset($_GET['status']) && '1' == $_GET['status']) {
// status == '1'
}
评论
0赞
Nico David
6/19/2013
警告已消失,但现在会显示进程之前不应显示的状态。
0赞
jterry
6/19/2013
if(isset($_GET['status']=='1'))
无效...您必须将这两个参数分开。if
0赞
Nico David
6/19/2013
先生,如何区分它?
0赞
jterry
6/19/2013
请看我的答案:) - 说“检查 x 和 y” - 这就是为什么 和 检查被它分开的原因。&&
isset()
==
0赞
Angelo R.
6/19/2013
#2
您可以在文件顶部尝试如下操作
$statusExists = array_key_exists('status', $_GET);
然后你可以很容易地做一些事情,比如
if($status && $_GET['status'] == '1') {
// whatever
}
else if($status && $_GET['status'] == '0') {
// whatever else
}
此问题源于以下事实:在此处理阶段,“status”不作为查询字符串的一部分存在 - 因此它只是出错。现在,提供的代码会检查状态键是否存在,然后检查该值。
0赞
user1864610
6/19/2013
#3
我在您的表单中没有看到名称为 的表单元素。如果它不存在,也不会存在。status
$_GET['status']
问题在于语法错误 - 您以某种方式输入了错误。isset
下一个:未定义的偏移量通知似乎是错误的
评论