-5

好的,所以我编写了以下代码:

Acum adaugati note si absente pentru&nbsp;<?php echo $numeleelevuluiales ?>, la materia <?php echo $numelemateriei ?> :
<br />
<?php
if(!isset($_POST['submit13']))
{
    ?>
    Adauga o nota noua:

    <form method="post" action="" name="form666">
    <table border="0" cellspacing="0" cellpadding="0"> 
      <tr>

        <td  width="50">Nota: &nbsp;

        <select name="note">
    <option value="eroare">Alege nota</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    </select>
    </td>
    <td   width="50"> Ziua:&nbsp;
    <select name="ziua">
    <option value="eroare1">Alege ziua</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>

    </td>
    <td   width="50">Luna: &nbsp;
    <select name="luna">
    <option value="eroare2">Alege luna</option>

    <?php
    $lunile = "SELECT id, luni
        FROM luni";
    $qlunile = mysql_query($lunile);

    while($luniletabel = mysql_fetch_array($qlunile))
    {
        echo "<option value='".$luniletabel['id']."' name='luna'>" . $luniletabel['luni'] . "</option>";
    }
     ?>
    </select>

    </td></tr>

      </table> <br />
         <input type="submit" name="submit13" value="&nbsp;Adauga &nbsp;" >
         </form><br />
    <?php

}//sfarsit if
else
{
    if(!isset($_POST['submit333']))
    {
        if($_POST['note'] == 'eroare' || $_POST['ziua'] == 'eroare1' || $_POST['luna'] == 'eroare2' )
        {
            echo "EROARE!!! Nu ati ales toate campurile <br />";
        }
        else
        {
            echo "Ati ales nota&nbsp;" .$_POST['note'].", in ziua&nbsp;" .$_POST['ziua']. ", si luna a " .$_POST['luna']. ".";
            ?><br />
            Daca datele sunt corecte, apasati butonul de mai jos pentru adaugarea in baza de date:


             <form method="post" action="" name="form666">
             <input type="submit" name="submit333" value="&nbsp;Adauga in baza de date&nbsp;" >
                 </form>
            <?php
        }
    }
    else // daca a fost apasat submit 333
    {
        $azi = new DateTime(date("Y-m-d"));
        //
        $data_adaugare = $azi->format("Y-m-d");
        //
        // se adauga cele 2 zile
        //
        $termen = 2; // zile de modificare
        //
        $azi->add(new DateInterval('P2D'));
        //
        $data_expirarii = $azi->format("Y-m-d");

        $materianote = $_SESSION['materienote'];
        $id_note = $_POST['note'];
        $data_nota = $_POST['ziua'];
        $luna_nota = $_POST['luna'];
        echo $id_note;

        mysql_query("INSERT INTO note(id_elev, id_materie, id_note, data_nota, luna_nota, data_adaugare, data_expirare) 
                VALUES ($codul_elevului, $materianote, $id_note, $data_nota, $luna_nota, $data_adaugare, $data_expirarii) ")
                or die("Hopa! Ceva nu merge!");
        echo "Adaugat cu succes!";


    }//sfarsit if isset submit 333

}//sfarsit daca sunt alese toate campurile


}

问题就在这里:else // daca a fost apasat submit 333 当我按下“submit333”提交按钮时,else 中的任何内容都不起作用。我尝试在 else 语句中回显某些内容,但没有任何效果。

有任何想法吗?我做错了什么?

MySql 没问题。谢谢大家的回答!

4

1 回答 1

3

你的逻辑有缺陷。

删除所有其他内容后,您的代码归结为:

if(!isset($_POST['submit13']))
{
}
else
{
  if(!isset($_POST['submit333']))
  {
  }
  else
  {
    // here is where you want stuff to happen when $_POST['c'] is set
  }
}

但是如果你按下了提交按钮submit333,那么你很可能没有同时按下提交按钮submit13,对吧?

而且因为你没有submit13,你的代码进入了第一个if块,所以它不会进入else属于第一个的分支if,所以你的第二个if甚至永远不会执行......</p>

于 2013-10-09T15:34:35.677 回答