PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Apr 20, 2018 1:03 pm

All times are UTC - 5 hours




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

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 197
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: 6617
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: 17
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  
 
PostPosted: Tue Dec 19, 2017 3:10 am 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 197
benanamen wrote:
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


Requinix knows I cross-post on many forums under this Username and he suspects (according to his pm) I am the same person using another Username in another forum but I did a little acting to throw him off the rails and now he is not so sure it's the same person under that different Username in that other forum. And so he went quiet with his lashing-out PMs fearing he'd make a fool of himself if it is another person he's lashing out on. But, he may realize things after reading this. Lol!


Top
 Profile  
 
PostPosted: Tue Dec 19, 2017 7:50 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13541
Location: New York, NY, US
UniqueIdeaMan wrote:
Requinix knows I cross-post on many forums under this Username and he suspects (according to his pm) I am the same person using another Username in another forum but I did a little acting to throw him off the rails and now he is not so sure it's the same person under that different Username in that other forum. And so he went quiet with his lashing-out PMs fearing he'd make a fool of himself if it is another person he's lashing out on. But, he may realize things after reading this. Lol!

I don't think you understand how horribly inappropriate this comment is. These forums are a resource where answers and advice are given for technical problems -- for free. I cannot state more strongly that the help is provided for free by volunteers our of the goodness of their hearts. That such goodness exists in the online technical community is to me one of great things in this world. Volunteers like requinix and Celauran volunteer their time unselfishly to help others. That help is actually pretty expensive when provided professionally. That anyone would be abuse that good will is simply disgusting. I think an apology to Requinix would be appropriate.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Tue Dec 19, 2017 9:45 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
UniqueIdeaMan wrote:
Requinix knows I cross-post on many forums under this Username and he suspects (according to his pm) I am the same person using another Username in another forum but I did a little acting to throw him off the rails and now he is not so sure it's the same person under that different Username in that other forum.

I have repeatedly told you that I knew you're the same person. I've even explained how I knew. I didn't mention that you've slipped up twice in the past by saying something that is only possible if you had all the accounts. And now you're actually stating it? Publicly? When you know I'm here? You do not make sense.

UniqueIdeaMan wrote:
And so he went quiet with his lashing-out PMs fearing he'd make a fool of himself if it is another person he's lashing out on.

I don't visit your threads because the only things I have to say to you are insulting. I try not to, and I've even managed to be helpful here a couple times. But lately on DevShed I gone out of my way to be mean to you - and unfortunately you're still there. The only thing positive I have to say about you is that you haven't returned to PHP Freaks after we kicked you out, which demonstrates more common sense than I ever thought you had.

Christopher wrote:
I think an apology to Requinix would be appropriate.

Oh no, that's not necessary. I mean, I've been trash-talking this guy to his face. The only apology he owes is to the world for his continued existence.


Top
 Profile  
 
PostPosted: Tue Feb 06, 2018 2:54 am 
Offline
Forum Newbie

Joined: Tue Feb 06, 2018 2:33 am
Posts: 5
using this code to solve your problem
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// sql to delete a record
$sql = "DELETE FROM MyGuests WHERE id=3";

if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>


Top
 Profile  
 
PostPosted: Tue Feb 06, 2018 6:54 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
+1 requinix
+1 Christopher

Just supporting them that some people do not deserve help by the open community. dot .

PS: UniqueIdeaMan is in my ignore list since I recently started actively posting in this forum again. Just few of his posts were enough to make this decision.

_________________
There are 10 types of people in this world, those who understand binary and those who don't


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 18 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