以下代碼適用於$ _GET,但不適用於$ _POST。POST不工作,而不是GET
<?php
include_once 'dbconfig.php';
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM users WHERE user_id=".$_GET['delete_id'];
mysqli_query($conn,$sql_query);
header("Location: $_SERVER[PHP_SELF]");
}
?>
<script type="text/javascript">
function edt_id(id)
{
if(confirm('Sure to edit ?'))
{
window.location.href='edit_data.php?edit_id='+id;
}
}
function delete_id(id)
{
if(confirm('Sure to Delete ?'))
{
window.location.href='index.php?delete_id='+id;
}
}
</script>
</head>
<body>
<center>
<div id="body">
<div id="content">
<table align="center">
<tr>
<th colspan="5"><a href="add_data.php">add data here.</a></th>
</tr>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City Name</th>
<th colspan="2">Operations</th>
</tr>
<?php
$sql_query="SELECT * FROM users";
$result_set=mysqli_query($conn,$sql_query);
while($row=mysqli_fetch_row($result_set))
{ ?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td align="center"><a href="javascript:edt_id('<?php echo $row[0]; ?>')"><img src="b_edit.png" align="EDIT" /></a></td>
<td align="center"><a href="javascript:delete_id('<?php echo $row[0]; ?>')"><img src="b_drop.png" align="DELETE" /></a></td>
</tr>
<?php
} ?>
</table>
</div>
</div>
</center>
</body>
</html>
我已更改isset值並查詢以發佈而不是get。但是當數據表的數據刪除按鈕不起作用時。在isset中更改get方法並查詢並刷新頁面後,行將被刪除。它的原因是什麼?