我的實現似乎不工作。你能指出什麼可能是問題或指向我更好的解決方案嗎?當我檢查複選框並點擊刪除按鈕時,它似乎沒有做任何事......請幫助我。PHP複選框多刪除
<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="postItDiv" class="page">
<?php
$cxn = mysqli_connect('localhost', 'root', 'root', 'TimePost') 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'];
$postColor = rand(1, 4);
echo '<div id="post1"><p class="postParagraph">Post ID No.' . $idNo . '<br />' . $post . ' at ' . $time . ' seconds mark</p><div class="close"><form method="POST" action="videoJudge.php"><input type="checkbox" name="checkbox[]" id="checkbox[]" value="' . $idNo . '" /></form></div></div>';
}
if($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['btnPost']) {
$postColors = rand(1, 4);
$toPost = $_POST['textPost'];
$date = date("y-m-d");
$postTime = $_POST['display'];
$postTime = floor($postTime);
$insertPostQuery = "INSERT INTO tblTimePosts VALUES('','Mimagazine Asia','Chelsea','$postTime','$toPost','$date')";
$query3 = "SELECT PostID FROM tblTimePosts";
$result = mysqli_query($cxn, $insertPostQuery) or die(mysqli_error());
$result3 = mysqli_query($cxn, $query3) or die(mysqli_error());
if($result > 0) {
while($row = mysqli_fetch_assoc($result3)) {
$idNo2 = $row['PostID'];
}
echo '<div id="post1"><p class="postParagraph">Post ID No.' . $idNo2 . '<br />' . $toPost . ' at ' . $postTime . ' seconds mark</p><div class="close"><form method="POST" action="videoJudge.php"><input type="checkbox" name="checkbox[]" id="checkbox[]" value="' . $idNo2 . '" /></form></div></div>';
}
else
echo "Add Failed";
}
/* if($_POST['chkDelete']) {
for($i=0;$i<5;$i++){
$del_id = $checkDelete[$i];
$sql = "DELETE FROM $tblTimePosts WHERE PostID='$del_id'";
$resulta = mysqli_query($cxn,$sql);
}
} */
if($_POST['btnDelete']) { // from button name="delete"
/* $checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
echo $countCheck;
for($i=0;$i<$countCheck;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM tblTimePosts WHERE PostID=".$del_id."";
$resulta = mysqli_query($cxn,$sql) or die(mysqli_error());
} */
$tbl_name = 'tblTimePosts';
foreach($_POST['checkbox'] as $id => $value) {
$sql = 'DELETE FROM `' . $tbl_name . '` WHERE `PostID`=' . (int) $id;
mysqli_query($cxn, $sql);
}
header('Location: videoJudge.php');
}
?>
</div>
<div id="videoContainer" class="page">
<video id="video" poster="images/cover.png" controls>
<source src="video/animationTest.m4v" />
</video>
</div>
<div id="etc" class="page">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<textarea name="textPost" id="textPost">
</textarea>
<input type="submit" name="btnPost" id="btnPost" value="Post" />
<div id="tae">
<input type="text" name="display" id="display" value="0" />
</div>
</form>
</div>
<div id="delButtonDiv">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="submit" value="Delete" name="btnDelete" />
</form>
</div>
</div>
這是我的代碼現在後,所有的評論,但仍然沒有工作。 :(
<?php
$cxn = mysqli_connect('localhost','root','root','TimePost') 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'];
$postColor = rand(1,4);
echo '<div id="post1"><p class="postParagraph">Post ID No.'.$idNo.'<br />'.$post.' at '.$time.' seconds mark</p><div class="close"><form method="POST" action="videoJudge.php"><input type="checkbox" name="checkbox[]" id="checkbox[]" value="'.$idNo.'" /></form>
</div></div>';
}
if ($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['btnPost']) {
$toPost = $_POST['textPost'];
$date = date("y-m-d");
$postTime = $_POST['display'];
$postTime = floor($postTime);
$insertPostQuery = "INSERT INTO tblTimePosts VALUES('','Mimagazine Asia','Chelsea','$postTime','$toPost','$date')";
$query3 = "SELECT PostID FROM tblTimePosts";
$result = mysqli_query($cxn, $insertPostQuery) or die(mysqli_error());
$result3 = mysqli_query($cxn, $query3) or die(mysqli_error());
if ($result > 0) {
while($row = mysqli_fetch_assoc($result3)) {
$idNo2 = $row['PostID'];
}
echo '<div id="post1"><p class="postParagraph">Post ID No.'.$idNo2.'<br />'.$toPost.' at '.$postTime.' seconds mark</p><div class="close"><form method="POST" action="videoJudge.php"><input type="checkbox" name="checkbox[]" id="checkbox[]" value="'.$idNo2.'"
/></form></div></div>';
}
else
echo "Add Failed";
}
if($_POST['btnDelete'] == "Delete")
{
$tbl_name = 'tblTimePosts';
foreach ($_POST['checkbox'] as $id => $value)
{
$sql = 'DELETE FROM `'.$tbl_name.'` WHERE `PostID`='.(int)$id;
mysqli_query($cxn,$sql);
}
header('Location: videoJudge.php');
}
?>
</div>
<div id="videoContainer" class="page">
<video id="video" poster="images/cover.png" 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="tae">
<input type="text" name="display" id="display" value="0" />
</div>
<div id="delButtonDiv">
<input type="submit" value="Delete" name="btnDelete" />
</div>
</form>
</div>
你是什麼意思兩種形式?我應該在哪裏放置我的刪除代碼塊? – 2011-12-15 15:11:45
什麼都沒有發生先生。仍然沒有任何反應:( – 2011-12-15 15:21:24