简体   繁体   中英

How to make to submit button, delete and update at the same form,php

I am making a form that when user check one row with check button he can delete or update it...But only the delete button work.I dont know how to make two submit buttons in the same form. I want the delete button when pressed to go to delete.php and update button to go two update.php...Below is my form...

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

Please help me.Thanks in advance

you should change the values of your buttons like this

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

and then at your "delete.php" page check which one of them you want to

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

I dont know how to port them to different pages directly without javascript, but you can check if the delete button is pressed with php like this

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

with jquery you can also change the actual file. Like this

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");
        }
 });

Refer this :

Multiple submit buttons php different actions

Put this script in your page :

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

Modify your input code :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM