데이터베이스에서 쿼리를 삭제하려면이 테이블에 삭제 버튼을 추가하고 싶습니다. 나는 여기 Ajax와 PHP 코드가 있습니다jQuery를 사용하여 데이터베이스에서 레코드 삭제
<?php
require_once 'dbconfig.php';
$stmt = $pdo->prepare("SELECT * FROM test");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['server']; ?></td>
<td><?php echo $row['reference']; ?></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="images/delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
아약스 :
$(document).ready(function(){
/* Data Delete Starts Here */
$(".delete-link").click(function()
{
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");
if(confirm('Sure to Delete ID no = ' +del_id))
{
$.post('delete.php', {'del_id':del_id}, function(data)
{
parent.fadeOut('slow');
});
}
return false;
});
/* Data Delete Ends Here */
});
delete.php :
선택한 행이 보이지 않는다는 DB에서 삭제하려면
<?php
include_once 'dbconfig.php';
if($_POST['del_id'])
{
$id = $_POST['del_id'];
$stmt=$db_con->prepare("DELETE FROM test WHERE id=:id");
$stmt->bindParam(':id', $id);
$stmt->execute();
}
?>
... 나는 아무런 오류도 없다.
데이터 : {id : id}, 이와 같은 데이터를 전달하십시오. 제발 –
이봐, 미안하지만 이해가 안돼 ... 좀 더 노골적이 될 수 있니? – Xibition