나는 하나의 양식을 가지고 있으며 제거 단추가있는 여러 양식 필드가 있습니다. 모든 데이터는 DB.now에서 오는 것입니다. 제거 단추를 클릭하면 DB에서이 데이터를 제거하고 싶습니다. 아약스.PHP에서 데이터 삭제 PHP와 AJAX를 사용하여
PHP 코드 : -
<?php
for($i=0;$i<$hdntotal;$i++)
{
?>
<div class="expform" id="<?=$i;?>">
<label class="explabel">Expert Name: </label><input type="text" id="txtexpname" name="txtexpname[]" class="expfield" placeholder="Enter name of expert" value="<?=$expert_name[$i]; ?>"/>
<div class="clearboth"></div>
<label class="explabel">Link of the expert work: </label><input type="text" id="txtexplink" name="txtexplink[]" class="expfield" placeholder="Enter link of expert work" value="<?=$expert_user_links[$i];?>"/>
<div class="clearboth"></div>
<label class="explabel">Title of the review: </label><input type="text" id="txtreviewtitle" name="txtreviewtitle[]" class="expfield" placeholder="Enter title of review" value="<?=$expert_title[$i];?>"/>
<div class="clearboth"></div>
<label class="explabel">Details of the review: </label>
<textarea id="txtrevdetails" name="txtrevdetails[]" class="expfield" placeholder="Enter details of review"><?=$expert_details[$i]; ?></textarea>
<div class="clearboth"></div>
<input type="hidden" value="<?=$rev_id[$i];?>" name="oldexprevids[]" >
<input type="button" class="delReview" id="<?=$rev_id[$i];?>" value="Remove">
<div class="line"></div>
</div>
<?php
}
?>
JS 코드 : -
/*AJAX Function for Delete Expert Review*/
jQuery(document).ready(function($) {
$('button.delReview').each(function(){
var $this = $(this);
$this.click(function(){
var deleteItem = $this.attr('id');
$.ajax({url:'delete-expreview.php?action='+deleteItem}).done(function(data){
//colect data from response or custom code when success
});
return false;
});
});
});
/*End fo AJAX Function*/
삭제 페이지 코드 : -
$id = $_REQUEST['action'];
$sql5 = "delete from cc_tbl_car_review where id = '$id'";
$result5 = mysqli_query($db,$sql5) or die('Fetch Error');
하지만 난 점점 아니에요 어떤 결과가 있다면 어떤 결과가 나옵니다. 나와 공유하십시오.
삭제 페이지에서 $ _REQUEST [ 'action'] 값을 얻고 있습니까? (inspect 요소/네트워크 콘솔을 통해 확인 했습니까?) ?? –