3 回答

TA貢獻1866條經驗 獲得超5個贊
你有兩種方法:
1:
使用GET方法:
<a href="/delete.php?id='.$row['car_id'].'" class='btn btn-outline-danger text-white'>DELETE</a>
在delete.php中:
$id=$_GET['id'];
并查詢刪除。
2:
使用ajax:
<button value="'.$row['car_id'].'" class="btn btn-outline-danger text-white" onclick="Delete(this)">DELETE</button>
js:
function Delete(elem) {
var id= elem.value;
$.ajax({
url: "delete.php",
type: "POST",
data: {id: id},
success: function (data) {
alert('Done');
}
});
}
在delete.php中:
$id=$_POST['id'];
并查詢刪除。
請改進您的所有查詢。(準備 stmt)

TA貢獻1773條經驗 獲得超3個贊
您可以使用帶有操作按鈕名稱的表單來標識要執行操作的哪一部分
<?php
if(isset($_POST['delete_rows'])) { //<-- see input name
... delete anything from database ...
} else
if(isset($_POST['select_rows'])) { //<-- see input name
... select anything from database ...
}
?>
<form method="post">
<input type="submit" name="delete_rows" value="Delete"/>
<input type="submit" name="select_rows" value="Select"/>
</form>

TA貢獻1772條經驗 獲得超6個贊
您可以通過兩種方式完成此操作
1-您可以創建一個超鏈接并將行值傳遞給它,就像<a herf="page.php ? Id= $row['id']>del</>
2-您可以在表單方法 post 中創建一個按鈕并發布 id 并刪除記錄。
注意:在 php 中,它使用名稱標簽而不是 id
我希望這個答案對你有幫助
- 3 回答
- 0 關注
- 211 瀏覽
添加回答
舉報