-1

免责声明这是一个学校项目,因此可以使用 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="&nbsp;Alege &nbsp;" >
     </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="&nbsp;Alege &nbsp;" >
     </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'];***
  }

愚弄我!!!我通过查看这里的代码解决了这个问题。问题是我没有在帖子中使用选择名称标签,但我使用了选项名称标签。现在它正在工作!

4

2 回答 2

2

这不是<select>工作方式。

假设你有

<select name="nameOfTheSelect">
<option value="x">sample value</option>
<option value="y">another value</option>
</select>

并且用户选择第二个值(另一个值)并发布它,您将收到它:

$_POST['nameOfTheSelect'] == 'y';

所以,<option>没有它自己的名字,因为它是一个值。你没有$_POST['y']这里(在你的情况下$_POST['materili']

于 2013-10-08T10:39:07.960 回答
1

您需要更改以下内容:

<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>

<select name="elivi">
<option value="">Alege elevul</option>
   <?php
 while($elevii = mysql_fetch_array($elevul))
{

      echo "<option value='".$elevii['cod_elev'].">" . $elevii['prenume_elev'] . "</option>";

  }
  ?>
  </select>

您不能name<option>. name应该进去<select>

于 2013-10-08T10:38:52.670 回答