2014-02-15 21 views
2

我正在做一個表格,當用戶檢查一行與檢查按鈕,他可以刪除或更新它......但只有刪除按鈕work.I不知道如何在同一個表單中創建兩個提交按鈕。我想按去delete.php和更新按鈕走兩頭update.php時刪除按鈕......下面是我的形式...如何使提交按鈕,刪除和更新在相同的形式,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> 

請幫助me.Thanks提前

+0

你可以這編寫一個intermediate.php,它根據點擊的按鈕決定導航哪個地方。就像if buttonClicked ='delete'then goto delete.php else goto update.php – Habrashat

+0

不要使用 optional

回答

0

我不知道如何將它們移植到不同的頁面的情況下直接的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"); 
     } 
}); 
0

參見本:

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

你應該改變你的按鈕的值這樣

<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'} 
相關問題