I have Below Form 5-10:-
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="9" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="8" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="7" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="6" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="5" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
<div id="post">
<form method="post" action="javascript:alert('success')" >
<input id="postid" type="hidden" name="post" value="4" />
<input id="unique" type="hidden" name="unique" value="<?php echo $unique; ?>" />
<input type="submit" value="Submit" name="submit" />
</form>
</div>
AND I HAVE below jquery to perform ajax and delete that particular post, but it is not performing delete.
<script type="text/javascript">
$(document).ready(function(){
$("#post").submit(function() {
var postid = $('#postid').val();
var unique= $('#unique').val();
var str = 'unique='+ unique+ '&postid='+ postid;
$.ajax({
type: "POST",
url: "delete.php",
data: str,
success: function(msg) {
$("#post").ajaxComplete(function(event, request, settings) {
if (msg == 'OK')
{
result = '<div style="color:red;">Something Went Wrong</div><br />';
} else {
result = msg;
}
$("#post").html(result);
});
}
});
return false;
});
});
</script>
my PHP delete code :-
<?php
if($_POST['unique'] === $_SESSION['unique']) {
$delete = $mysqli->query("DELETE from post where postid='".$mysqli->real_escape_string($_POST['postid'])."'");
echo "DELETED";
} else {
echo "OK";
}
?>
It is not deleting post when submit function is pressed... I want to delete that particular postid whenever user submit any particular form...