PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Dec 15, 2017 10:20 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Oct 14, 2017 8:03 pm 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 179
Folks,

Here is a php code that lists all the rows and columns in your mysql tbl for you to select the rows (via check boxes) you want to delete and then delete them by clicking the appropriate "delete" buttons.
Problem is, when I click any of the "delete" buttons, I get error flicking for a sec that there is an undefined variable $num. But, the $num has been defined. So, should not be getting this error and the selected row should get deleted.

Syntax: [ Download ] [ Hide ]
    <?php

    require "conn.php";

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Follow Users</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="form" action="" method="post">
    <table border=1 cellpadding=1 cellspacing=1>
            <tr>
                    <th>Id</th>
                    <th>Username</th>
                    <th>Password</th>
                    <th>Email</th>
                    <th>Delete</th>
            </tr>
    <?php
    $res=mysqli_query($conn,"SELECT * FROM users");
    while($row=mysqli_fetch_array($res))
    {
            echo "<tr>";
            echo "<td>"; echo $row["ids"]; ?> <input type="checkbox" name="num[]"
    class="other" value="<?php echo $row["ids"]; ?>" /> <?php echo "</td>";
            echo "<td>"; echo $row["usernames"]; echo "</td>";
            echo "<td>"; echo $row["passwords"]; echo "</td>";
            echo "<td>"; echo $row["emails"]; echo "</td>";
            echo "<td>"; echo "<input type='submit' name='submit' value='delete
    selected'>"
; echo "</td>";
            echo "</tr>";
    }
    ?>
    </table>
    </form>
    <?php
    if(isset($_POST["submit"]))
    {
       $box=$_POST['num'];
       while (list ($key,$val) = @each ($box))
            {
          mysqli_query($conn,"DELETE FROM users WHERE id='$val'");
        }
    ?>
           <script type="text/javascript">
           window.location.href=window.location.href;
           </script>
    <?php
    }
    ?>

    </body>
    </html>


 


Top
 Profile  
 
PostPosted: Sat Oct 14, 2017 8:34 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6606
Location: WA, USA
$_POST[num] will only exist if at least one checkbox was checked.


Top
 Profile  
 
PostPosted: Mon Oct 16, 2017 5:56 pm 
Offline
Forum Newbie

Joined: Sun Nov 15, 2015 12:57 pm
Posts: 12
OP is already wasting the time of, I mean, getting answers from the other forums he cross posts the same exact questions to multiple times.
http://forums.devshed.com/php-development-5/mysql-row-deletion-fails-979264.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group