同一 PHP 页面上的不同提交按钮

Different submit button at the same PHP page

我想问一下在同一个页面上使用多个提交按钮的方法 以下是过程:首先用户从 select 列表中做出选择并单击有效,然后将显示一个包含另一个操作的数组

问题是只有第一个提交按钮处于活动状态,而第二个按钮不起作用

一个表单,只能提交一个。因此,如果您想要两次提交,请创建两个表单。

 //here is the first code for the select list


<header class="panel-heading ">
                                <form action="index2.php" method="post" name="a">          <!-- first form  for the select list-->
                                    <fieldset> 
                                       Veuillez selectionnez un chantier : &nbsp;&nbsp;&nbsp;
                                     <select name="chantier" class=" dropdown-toggle"> 
                                            <option value="NULL">-- Selectionner --</option> 
                                            <?php 

                                    include"config.php";
                                     $str = $_SESSION['username'] ; 

                                    $query = " SELECT dbo.CH_PROTUSER.CH_Designation, dbo.CH_PROTUSER.CH_Num, 
                                    dbo.CH_ACCES.U_Login FROM dbo.CH_PROTUSER INNER JOIN dbo.CH_ACCES ON
                                    dbo.CH_PROTUSER.CH_Num = dbo.CH_ACCES.U_CHNUM Where dbo.CH_ACCES.U_Login= '$str' ";
                                    $result = sqlsrv_query($conn, $query);
                                    while( $rs = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC) ){
                                    ?>
                                    <option value="<?php echo $rs['CH_Num'];   "<option id='". $rs['CH_Num'] ."'>"?>" ><?php echo $rs['CH_Designation'] ?></option> <?php }
                                    $s=($_POST['chantier']);
                                    echo $s;
                                     ?>
                                </select>

                                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="submit"  value="Valider"  class="btn btn-success btn-xs " i class="fa fa-check"></i>

                                    </fieldset> 
                                </form>
                            </header>

//这里是数组中第二种形式的第二个代码

           echo' <div class="row">
                <div class="col-sm-12">
                    <section class="panel">
                        <header class="panel-heading ">
                            Resultats
                        </header>
                        <table class="table responsive-data-table data-table">
                        <thead>
                                <tr>
                                    <th><center>CodeMDP</center></th>
                                    <th><center>Matricule</center></th>
                                    <th><center>Prenom</center></th>
                                    <th><center>Nom</center></th>
                                    <th><center>H.Norm</center></th>
                                    <th><center>H.DIV</center></th>
                                    <th><center>H.Supp</center></th>
                                    <th><center>Dimanche</center></th>
                                    <th><center>Ferier</center></th>
                                    <th><center> Modfier</center> </th>
                                    <th><center> Suprrimer</center> </th>
                                </tr>
                                </thead>
                                <tbody>';

                                while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC) ){

                                    $xss =$row['P_MATRICULE'];

                                        echo "<tr><td>" .'<center>' . $row['P_CODECHT'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_MATRICULE'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_PRENOM'] .'</center>'. "</td>
                                        <td>"  .'<center>'. $row['P_NOM'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HNORM'] .'</center>'. "</td> 
                                        <td>" .'<center>'. $row['P_HEURDIV'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HEURSUP'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HDIMANCH'] .'</center>'. "</td>
                                        <td>" .'<center>'. $row['P_HFERIER'] .'</center>'. "</td>
                                        <td>  <form action='' method='post' name='b'> " ."<center><button data-toggle='modal' Type='submit' name='xyz'  
                                        value='$xss' class=' btn btn-info' href='#myModal' ><i class='fa  fa-pencil' ></i></center> ". "</form></td>
                                        <td>" ."<center><button data-toggle='button' class=' btn btn-danger' name='xyz'  ><i class='fa fa-trash-o' ></i></button></center> ". "</td>
                                            </tr>"; 
                                        }   
                                         if(isset($_POST['xyz'])) { 
                                             echo"aa";
                                        $sss="$xss";
                                        $query2 = " SELECT P_HNORM,P_HEURDIV,P_HDIMANCH,P_HFERIER,P_HEURSUP
                                        FROM [C_POINTAGESEMPLOYE] WHERE P_MATRICULE = '$sss'  AND (SELECT CONVERT(VARCHAR(8), P_DATETX, 12) 
                                         AS [MM-DD-YY])   = (SELECT CONVERT(VARCHAR(8), GETDATE(), 12) AS [MM-DD-YY])";
                                          $result2 = sqlsrv_query($conn, $query2);
                                          while( $row2 = sqlsrv_fetch_array( $result2, SQLSRV_FETCH_ASSOC) )
                                        {
                                        $hn =($row2['P_HNORM']);
                                        $hd =($row2['P_HEURDIV']);
                                        $hs =($row2['P_HEURSUP']);
                                        $hdim =($row2['P_HDIMANCH']);
                                        $hf =($row2['P_HFERIER']);
                                        }
                                         }

                                    echo'
                            </tbody>
                        </table>


                    </section>

                </div>
                </div>
            <div class="row">
                <div class="col-md-12">
                     <section class="panel">
                        <header class="panel-heading ">                        
                            <p align="right">                      
                            <button type="button" class="btn btn-success "><i class="fa fa-check"></i>&nbsp;&nbsp; Confirmer </button>
                            </p>

                        </header>
                    </section>
                </div>
            </div>
            </div>' ;

您可以通过单击第一个按钮使用 Ajax GET 请求,并为带有提交按钮的表单的第二个 POST 请求附加元素。但是如果你想使用两个提交你必须有两个表单或者唯一的方法是如果两个表单相等。 从 HTML 进行 SQL 查询是完全错误的 !!! 已编辑

例子

  $('#selectbox1').change(function() { var data = ""; $.ajax({ 
    type:"GET", 
    url : "controller mapping", 
    data : "selectbox1_selectedvalue="+$(this).val(), 
    async: false,
     success : function(response) { 
    data = response; 
    return response; 
    }, 
    error: function() { 
    alert('Error occured');
     } 
    }); 
    var string = data.message.split(","); 
    var array = string.filter(function(e){
return e;
});
  $.each(array, function(index, value) {
    //here it's your form with inputs.
    $('#form').append("<input name="inputName" value="value"/>");
     }); 
    $('#form').show()
    });

this is on select change