I am having a very hard time solving my problem with the multiple checkbox delete. Can someone direct me to the solution? What is supposed to happen here is that the user can tick the boxes and click a delete button to delete the ticked ones. Unfortunately, my code doesn't seem to work; can you point me in the right direction?
<div id="container" class="page">
<img id="disclaimer" class="page" src="images/DISCLAIMER.png" alt="" />
<img id="logo" class="page" src="images/MI-LOGO.png" alt="" />
<div id="videoContainer" class="page">
<video id="video" controls>
<source src="video/animationTest.m4v" />
</video>
</div>
<div id="etc" class="page">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
<textarea name="textPost" id="textPost">
</textarea>
<input type="submit" name="btnPost" id="btnPost" value="Post" />
<div id="displayOpacity">
<input type="text" name="display" id="display" value="0" />
</div>
<input type="submit" value="Delete" name="btnDelete" id="btnDelete" />
</div>
<div id="postItDiv" class="page">
<?php
$cxn = mysqli_connect('localhost','root','root','TimePost') or die(mysqli_error());
$selectQuery = "SELECT PostID, ClientName, VideoName, PostTime, Post, Date FROM tblTimePosts";
$selectResult = mysqli_query($cxn,$selectQuery) or die(mysqli_error());
while($row = mysqli_fetch_assoc($selectResult))
{
$postz = $row['Post'];
$timez = $row['PostTime'];
$idNoz = $row['PostID'];
echo '<div id="post1"><p class="postParagraph">Post ID No.'.$idNoz.'<br />'.$postz.' at '.$timez.' seconds mark</p><input type="checkbox" name="checkbox[]" id="checkbox[]" value="'.$idNoz.'"</input></div>';
}
if ($_POST['btnPost'] == "Post") {
$toPost = $_POST['textPost'];
$date = date("y-m-d");
$postTime = $_POST['display'];
$postTime = floor($postTime);
$insertQuery = "INSERT INTO tblTimePosts VALUES ('','Mimagazine Asia','Chelsea','$postTime','$toPost','$date')";
$insertResult = mysqli_query($cxn,$insertQuery) or die(mysqli_error());
$query = "SELECT PostID, ClientName, VideoName, PostTime, Post, Date FROM tblTimePosts";
$result = mysqli_query($cxn,$query) or die(mysqli_error());
while($row = mysqli_fetch_assoc($result))
{
$post = $row['Post'];
$time = $row['PostTime'];
$idNo = $row['PostID'];
echo '<div id="post1"><p class="postParagraph">Post ID No.'.$idNo.'<br />'.$post.' at '.$time.' seconds mark</p><input type="checkbox" name="checkbox[]" id="checkbox[]" value="'.$idNo.'"</input></div>';
}
}
else if($_POST['btnDelete'] == "Delete")
{
$tbl_name = 'tblTimePosts';
foreach ($_POST['checkbox'] as $id => $value)
{
$sql = 'DELETE FROM `'.$tbl_name.'` WHERE `PostID`='.(int)$id;
$resulta = mysqli_query($cxn,$sql);
if ($resulta > 0) {
echo "success";
}
else
echo "fail";
}
header('Location: videoJudge.php');
}
?>
</form>
</div>
<span id="copyright" class="page">Copyright © 2011<span style="color:#00AEEF;">mi</span>magazine.asia</span>
<span id="comment" class="page" style="color:#00AEEF;">comment/s</span>
<span id="download" class="page">(Right-click to download video)</span>
</div>