免责声明这是一个学校项目,因此可以使用 MYSQL。
所以,我想利用一些后期方法形式。我现在编写并重写了此代码 3 次。但它似乎并没有很好地将帖子值发送到帖子中......而且,我希望一旦选择一种形式就消失(以免混淆用户)。我设法在另一个版本中使用or, ||
运算符做到了这一点,但在这个版本中,我没有使用它,以保持简单。
这是代码
$clasa_elevului = $_SESSION['clasa'];
$scoala_elevului = $_SESSION['scoala'];
$judetul_elevului = $_SESSION['judet'];
?>
<a href="http://localhost/index.php?ex=8"> ALEGE ALT ELEV! </a><br />
<?php
if(isset($_POST['submit93']))
{
$_SESSION['elevi'] = $_POST['elevi'];
}
else //daca nu am apasat butonul de alegere a elevului
{
$alegeelevul = "SELECT cod_elev, prenume_elev
FROM elevi
WHERE id_clasa = $clasa_elevului AND id_scoala = $scoala_elevului AND id_judet = $judetul_elevului
ORDER BY cod_elev";
$elevul = mysql_query($alegeelevul);
?>
Alege elevul:
<form method="post" action="" name="form40">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><select name="scoala">
<option value="">Alege elevul</option>
<?php
while($elevii = mysql_fetch_array($elevul))
{
echo "<option value='".$elevii['cod_elev']."' name='elevi'>" . $elevii['prenume_elev'] . "</option>";
}
?>
</select>
</td></tr>
</table> <br />
<input type="submit" name="submit93" value=" Alege " >
</form>
<?php
}
/* PANA AICI TINE ELSE DACA NU AM APASAT BUTONUL DE TRIMITERE. DE AICI IN JOS ESTE MATERIA !!! DE AICI IN SUS E ELEVUL!!!! */
?>
<?php if(isset($_POST['submit10']))//daca e apasat butonul submit 10
{
$_SESSION['materii'] = $_POST['materii'];
}
else
{
?>
Acum alege materia :
<?php
$alege_materia = "SELECT
dmedia_didact.materii.id AS id,
dmedia_didact.materii.materie
FROM
dmedia_didact.materii INNER JOIN
dmedia_didact.materii_pe_clase ON dmedia_didact.materii_pe_clase.id_materie =
dmedia_didact.materii.id
WHERE dmedia_didact.materii_pe_clase.`id_clasa` = $clasa_elevului AND dmedia_didact.materii_pe_clase.`id_scoala` = $scoala_elevului ";
$materia = mysql_query($alege_materia);
?>
<form method="post" action="" name="form60">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><select name="scoala">
<option value="">Alege materia</option>
<?php
while($materii = mysql_fetch_array($materia))
{
echo "<option value='".$materii['id']."' name='materii'>" . $materii['materie'] . "</option>";
}
?>
</select>
</td></tr>
</table> <br />
<input type="submit" name="submit10" value=" Alege " >
</form><br />
<?php
} //sfarsit else daca NU am apasat submit 10
if(isset($_SESSION['elevi']))
{
echo $_SESSION['elevi'];
}
请注意,前 3 个会话变量工作正常。表单显示了它们的数据库内容。
它有什么问题?谢谢!
编辑:错误如下所示:Notice: Undefined index: materii in C:\wamp\www\index.php on line 620
第 620 行是这一行:
<?php if(isset($_POST['submit10']))//daca e apasat butonul submit 10
{
***$_SESSION['materii'] = $_POST['materii'];***
}
愚弄我!!!我通过查看这里的代码解决了这个问题。问题是我没有在帖子中使用选择名称标签,但我使用了选项名称标签。现在它正在工作!