1

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>

1 Answer 1

0

This HTML:

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

should be:

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.'" /></div>';

This query on else if($_POST['btnDelete'] == "Delete") should be:

$sql = 'DELETE FROM `'.$tbl_name.'` WHERE `PostID`='.(int)$value;
Sign up to request clarification or add additional context in comments.

4 Comments

life savior! thank you! But I have to refresh it everytime....y is it like that? is there a way to auto refresh it ?
by refresh, do you mean, this code header('Location: videoJudge.php'); ?
yep tnx again sir! now I have to move on to my next assignment. Is it possible to divide a html5 video seconds to frames?
you can move your delete code earlier in the code. that way, when you select the data, it is already cleaned. For html5, create another thread. Btw, can you vote up this answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.