while ループにフォームがあり、JQuery を使用してフォームを送信して mysql データベースからエントリを削除しようとしているという問題があります。問題は、削除を押すと、どの削除ボタンを押しても同じIDが送信されることです。
$("#deletePost").validate({
debug: false,
rules: {
},
//If the rules are not met, the following messages are displayed beside the input field.
messages: {
},
// do other stuff for a valid form
submitHandler: function(form) {
$.post('bin/Profile.php', $("#deletePost").serialize(), function(data) {
$('#ProfileWall').prepend( data );
});
}
});
});
<div id='ProfileWall'>
<?php
$WallRequest = mysql_query("SELECT * from WallPost where WallOf = '".$sn."' group by TimeAndDate DESC;")or die(mysql_error());
while($WallInformation = mysql_fetch_array($WallRequest))
{
$PostedBy = mysql_fetch_array(mysql_query("SELECT * from members where ServiceNumber = '".$WallInformation['PostedBy']."';"));
?>
<div id = "post_<?php echo $WallInformation["id"]; ?>" >
<form name = 'deletePost' id = 'deletePost' method = 'post'>
<table border = '0' width = '550' height = '60' valign = 'top' align = 'center'>
<tr valign = 'center'>
<td width = '10' valign = 'center'>
<input type = "hidden" name = "id" id = "id" value = "<?php echo $WallInformation['id']; ?>" >
<input type = "hidden" name = "sn" id = "sn" value = "<?php echo $sn; ?>" >
<input type = "submit" name="Delete" id = "Delete" value="Delete" class="delete" />
</td>
</tr>
</table>
</form>
</div>
<?php } ?>
</div>