-2

私は以下のフォーム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>

そして、ajaxを実行してその特定の投稿を削除するためにjqueryの下に持っていますが、削除を実行していません。

<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>

私のPHP削除コード:-

<?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";
}
?>

送信機能が押されたときに投稿を削除していません...ユーザーが特定のフォームを送信するたびに、その特定の投稿IDを削除したい...

4

1 に答える 1