【问题标题】:How to make to submit button, delete and update at the same form,php如何使提交按钮,删除和更新在同一个表单,php
【发布时间】:2014-03-15 04:06:07
【问题描述】:

我正在制作一个表单,当用户使用检查按钮检查一行时,他可以删除或更新它...但只有删除按钮有效。我不知道如何在同一个表单中制作两个提交按钮。我希望删除按钮按下去delete.php和更新按钮去两​​个update.php...下面是我的表格...

<form name="form1" method="post" action="delete.php">
<table >

  <th>

<th ><strong>Emri </strong></th>
<th ><strong>Pershkrimi </strong></th>
<th><strong>Ora</strong></th>
</th>

<?php

while ($row=mysql_fetch_array($result)) {
?>

<tr>
<td ><input name="checkbox[]" type="checkbox" value="<?php echo $row['Id_Akt']; ?>"></td>
<td style="font-size:0.9em"><?php echo $row['Emri']; ?></td>
<td ><?php echo $row['Pershkrimi']; ?></td>
<td><?php echo $row['Ora']; ?></td>
</tr>

<?php
}
?>


</table>
<input class="button" name="delete" type="submit" value="Fshij" style="margin-left:4%; margin-top:50px; width:15%">

<br>


<input class="button" name="update" type="button" value="Update" style="margin-left:4%; margin-top:20px; width:15%" >

</form>

请帮助我。在此先感谢

【问题讨论】:

  • 您可以编写一个intermediate.php,它根据单击的按钮决定要导航的位置。类似 if buttonClicked = 'delete' then goto delete.php else goto update.php
  • 不要使用

标签: javascript php mysql forms


【解决方案1】:

我不知道如何在没有javascript的情况下直接将它们移植到不同的页面,但是你可以像这样用php检查删除按钮是否被按下

 if(isset($_POST['delete']){
     //Delete was triggered
 }
 else{
     //Delete wasn't
 }

使用 jquery,您还可以更改实际文件。像这样

jQuery

$("input[type=submit]").click(function(e){
      $(this).addClass("e-clicked");       
}); 

 $("form").submit(function(){
        var vall = $(this).find(".e-clicked").attr("id");
        if(vall == "DELETEID"){
              $(this).attr("action", "deleteUrl.php");
        }
        else{
              $(this).attr("action", "updateUrl.php");
        }
 });

【讨论】:

    【解决方案2】:

    参考这个:

    Multiple submit buttons php different actions

    将此脚本放在您的页面中:

    <script>
        function submitForm(action)
        {
            document.getElementById('form1').action = action;
            document.getElementById('form1').submit();
        }
    </script>
    

    修改你的输入代码:

    <input class="button" name="delete" type="submit" onclick="submitForm('delete.php')" value="Fshij" >
    <input class="button" name="update" type="button" onclick="submitForm('update.php')" value="Update" >
    

    【讨论】:

      【解决方案3】:

      您应该像这样更改按钮的值

      <button type="submit" name="send" value="delete"> delete </button>
      <button type="submit" name="send" value="update">update</button>

      然后在您的“delete.php”页面检查您想要其中的哪一个

      if($_POST['send']=='update')
      { UPDATE table_name SET id='Your_ID' } 
      else 
      {DELETE FROM table_name WHERE id='Your_ID'}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-06
        • 2017-10-04
        • 1970-01-01
        • 2013-03-28
        • 1970-01-01
        相关资源
        最近更新 更多