I have a one form and which have multiple form fields with remove button.All data is coming from DB.now when i am click on remove button i want to remove this data from DB using ajax.
PHP Code:-
<?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 Code:-
/*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*/
Delete Page Code:-
$id = $_REQUEST['action'];
$sql5 = "delete from cc_tbl_car_review where id = '$id'";
$result5 = mysqli_query($db,$sql5) or die('Fetch Error');
But i am not getting any result.if you have any solution then please share it with me.