Page 1 of 1

Why Mysql Row Deletion Fails ?

Posted: Sat Oct 14, 2017 8:03 pm
by UniqueIdeaMan
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.

Code: Select all

    <?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>



Re: Why Mysql Row Deletion Fails ?

Posted: Sat Oct 14, 2017 8:34 pm
by requinix
$_POST[num] will only exist if at least one checkbox was checked.

Re: Why Mysql Row Deletion Fails ?

Posted: Mon Oct 16, 2017 5:56 pm
by benanamen
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-developme ... 79264.html

Re: Why Mysql Row Deletion Fails ?

Posted: Tue Dec 19, 2017 2:10 am
by UniqueIdeaMan
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-developme ... 79264.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!

Re: Why Mysql Row Deletion Fails ?

Posted: Tue Dec 19, 2017 6:50 pm
by Christopher
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.

Re: Why Mysql Row Deletion Fails ?

Posted: Tue Dec 19, 2017 8:45 pm
by requinix
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.

Re: Why Mysql Row Deletion Fails ?

Posted: Tue Feb 06, 2018 1:54 am
by pardeeptrivedi
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();
?>

Re: Why Mysql Row Deletion Fails ?

Posted: Tue Feb 06, 2018 5:54 pm
by VladSun
+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.