#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1

    Question Mysql Row Deletion Fails


    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. Not sure where to define it and how.
    Confesssion
    I actually play-paused 2 youtube videos and copy typed the code you see. That is one way I learn and gain a little work experience. Was not aware that the "each" function was deprecated until another told me.
    Even though, I checked the foreach loop tutorial, here I am at a loss how to make use of it. Feeling flabbergasted in my failure!

    PHP Code:
    <?php
    session_start
    ();
    require 
    "conn.php";
    require 
    "site_details.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"]; "</td>";
        echo 
    "<td>"; echo $row["passwords"]; "</td>";
        echo 
    "<td>"; echo $row["emails"]; "</td>";
        echo 
    "<td>"; echo "<input type='submit' name='submit' value='delete selected'>""</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>
    Here's another one. But, this one does not have the DELETE BUTTON. DELETE LINK instead. Same problem I'm facing on this one too. Not deleting anything.

    PHP Code:
    <?php
    session_start
    ();
    require 
    "conn.php";
    require 
    "site_details.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>
    <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 
    $sql 
    "SELECT * FROM users";
    $result mysqli_query($conn,$sql);
    while(
    $row mysqli_fetch_array($result))
        {
            echo 
    "<tr>";
            echo 
    "<td>".$row['ids']."</td>";
            echo 
    "<td>".$row['usernames']."</td>";
            echo 
    "<td>".$row['passwords']."</td>";
            echo 
    "<td>".$row['emails']."</td>";
            echo 
    "<td><a href=delete2a.php?id=".$row['ids'].">Delete</a></td>";
        }

    ?>
    </table>
    </body>
    </html>
    Can some good Samaritan fix the 2 codes so we beginners can learn from your examples ?
    I've come this far on these 2. Don't want to quit at the end.

    Cheers!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    103
    Rep Power
    65
    You are using the wrong column name in your delete query. If you had the mysqli error mode set to exceptions and php's error_reporting/display_errors set up properly, like you previously have used, you would know this, because you would be getting an error from the sql query.

    If you can't or won't 'internalize' the information that we have been providing to you (in this case, having error handling in your code) and the defining information in the php.net documentation (it's the source of all php language information), and consistently use this information in the same situation, you will never be able to create, test, and debug any code.

    Programming (any learning activity) requires a lot of inference, continuity, and consistency. You have not demonstrated any of these abilities. What you are doing is trying to mimic/ape things you have seen. This isn't learning. It's following along. You are acting like a production line assembly person who is putting part A on part B, attach with four screws, Part C. This method isn't going to work with programming. There are many more parts that you have to choose from and they can go together in many different ways.

    An analogy - remember paint by the numbers in Kindergarten? Paint all the '1' areas blue. Paint all the '2' areas green, ... The purpose of paint by the numbers was to teach recognizing numbers and color names, fine motor skills (keep inside the lines), and following instructions. It wasn't to teach how to become an artist and be able to create paintings. It was simply following along, doing a task by 'comparison'. It didn't teach all the different types of paint and canvas, which ones work together, and when to use each one.

    In order to create code that does something, you must learn enough of the language you are using so that you will know which of the statements you should even be using, how to correctly use each statement, and where to use them so that they contribute to the goal you are trying to accomplish. You must become an artist, not just an assembly person putting something together so that it matches what you have been taught it should look like.

    Comments on this post

    • Sepodati agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,352
    Rep Power
    630
    It would also help to use the numerous debugging techniques given here before posting a question. The OP seems to me to be a touch bit lazy in the reading and learning department and expects someone here to repeat the same answer each time the same mistakes are made.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by DSmabismad
    You are using the wrong column name in your delete query. If you had the mysqli error mode set to exceptions and php's error_reporting/display_errors set up properly, like you previously have used, you would know this, because you would be getting an error from the sql query.

    If you can't or won't 'internalize' the information that we have been providing to you (in this case, having error handling in your code) and the defining information in the php.net documentation (it's the source of all php language information), and consistently use this information in the same situation, you will never be able to create, test, and debug any code.

    Programming (any learning activity) requires a lot of inference, continuity, and consistency. You have not demonstrated any of these abilities. What you are doing is trying to mimic/ape things you have seen. This isn't learning. It's following along. You are acting like a production line assembly person who is putting part A on part B, attach with four screws, Part C. This method isn't going to work with programming. There are many more parts that you have to choose from and they can go together in many different ways.

    An analogy - remember paint by the numbers in Kindergarten? Paint all the '1' areas blue. Paint all the '2' areas green, ... The purpose of paint by the numbers was to teach recognizing numbers and color names, fine motor skills (keep inside the lines), and following instructions. It wasn't to teach how to become an artist and be able to create paintings. It was simply following along, doing a task by 'comparison'. It didn't teach all the different types of paint and canvas, which ones work together, and when to use each one.

    In order to create code that does something, you must learn enough of the language you are using so that you will know which of the statements you should even be using, how to correctly use each statement, and where to use them so that they contribute to the goal you are trying to accomplish. You must become an artist, not just an assembly person putting something together so that it matches what you have been taught it should look like.
    I did not go to Kindergarten but I do get your point.
    I did read the basics on php nearly 2 yrs back from tizag.com. Then halted for 1.5yrs. Now did a little revision from feb 2017 onwards from tutorialspoint.com and tutorialrepublic.com. Someone suggested codeacademy.com and did a little there. But, before starting on these latest 3 sites on this 2nd round of learning after 1.5yrs of break, I first started downloading about 100 youtube tutorials (a lot of them had deprecated stuff and I only found that out when they were pointed-out to me in the forums. That is why I bug the forums. Because, I learn from them one way or the other to what is old stuff and what is new) and play-pause copy their codes and test them. Whatever works, I keep them and learn from them and if I have any question on any line of code then I bug the forums (like I'm doing now). And so as it happens, before I revised my learning the basics I started on a project to build my own member reg-login site, build my own mini web proxy with cURL. I failed on the latter and so I took Mini Proxy and started adding my own features such as member accs (finished reg.php, login.php, logout.php, account_activation.php and now need to finish the home.php by giving a feature for the user to delete stuffs from the db tbl), banned words filter (still working on it) and url logger (finished it approx 3 mnths back). Will add keywords logger very soon. And then my member-reg login site is complete.
    Mostly, I don't bother trying to learn all the functions as they are too much and I easily forget what I learnt if I try learning too much or try taking in too much. That is why, I thought it is best I try learning or re-learning or try remembering only the functions that will become handy for me in my projects. Now, how to figure-out which ones will be handy and which ones not unless I embark on a project ? That is why I started on the member-reg-login site. 90% complete. You are wrong when you say I don't learn from the forums. I read on PREP STMT but nothing was really going in until mlukac89 (sitepoint.com) wrote the PREP STMT on registration.php & Kicken (here on devshed.com) wrote the PREP STMT for the account_activation.php. I then managed to do the PREP STMT on the login.php and now gonna do it on the home.php. See, had not these 2 fine folks given me the PREP STMT codes then I never would have been able to experiment with their codes and learn and gain work experience. I still have 2 questions on the PREP STMT and will open another thread about them. Anyway, my member reg-login site is nearly complete. After that, I will start a new project to build my own searchengine & crawler (downloaded lots of tutorials. I hope they are not old stuff. I'll find-out from you guys) and continue the mini web proxy from scratch project on the side.
    So that was a trailer of what I'm upto. And yes, yes, I've been told on other forums that I took on projects for the adv while I'm still a beginner. But who cares ? I managed to nearly finish the member reg login project in half a yr. Will turn that into a Social Network (SN) very soon by adding "Friends" and "Follow/Unfollow" and "Like" and "Share" systems. I downlaoded youtube tuts on how to build these. But I suspect there would be old coding. Therefore, I'll bug you guys here to convert them into new stuffs so we newbies learn the new stuffs and not deprecated stuffs.
    Oh! I nearly forgot to mention it. I build .exe bots or browser automation tools. I built:

    * back link finder
    * back link verifier
    * dofollow page/link verifier
    * auto search & scrape SEs
    * content spinner
    * wp blogs finder (find only those who have their commenting section open for you to comment and drop your links for backlink building)
    * wp blogs commenter
    * leads hunting on reddit
    * leads hunting on youtube (half built)
    * youtube messenger (half built)


    While I write this post an idea has come into my head to build:

    * leads hunting on wp
    * leads hunting on forums

    That means, I can build .exe bots to auto navigate, auto type, auto click links & buttons, auto scrape links & data.
    Now, gonna learn how to build web versions of these bots (.php) with php & cURL.
    So far, I have not sold any .exe bots. Just built them. Gonna use them soon and give them away for free. You guys can have copies. Might sell paid versions one day on warrior forum, fiverr, clickbank, jvzoo, etc.. Otherwise, just continue giving them away for free via youtube and the appropriate business related forums, groups and mailing lists.
    I will do the same with the .php versions.
    And so you see, I have a mission to complete. Therefore, don't have time to read-up on every single php function and digest them. Only gonna bother with those functions that will help me accomplish building my web versions of my bots. Keep tabs on me and see how far down the rabbit hole goes.
    And you guys are gonna aid me in learning cURL. I got to build a new member-reg-login site or SN where I only log-in to my account and my account will auto login to all the SNs I am registered with so I don't have to manually login to every one of them one by one (facebook, twitter, youtube, stumbleupon, digg, reddit, tumblr, etc.) and so I can search more than one searchengine simultanously (meta engine feature) . Like search google, youtube search, twitter search, digg search, reddit search, forum searches, etc.). Web automation through member-reg-login site or SN.
    In other words, we build .exe bots to automate the browser. Now gonna build web versions of the bots so can use the bots when on the road (train, plane, etc.) and away from home computer. And cURL is gonna make that dream come true. I will bug this forum while embarking on those projects and so keep tabs on my threads and contribute as much as you can. Even out if curiosity to learn what I'm upto.

    I'm just being honest with you guys to why I'm learning php & cURL. Whenever a good site idea comes into my head, I just want to build it. Period!

    OFF TOPIC:
    If you guys want any .exe bots then drop me a PM. Use it for your own personal use and/or give them away for free and/or license them. I don't care. Just make sure you build the .php versions and hand me over the code along with code comments for my learning. And don't have any problem if I GPL your code or give them away for free via forums, etc. or integrate them onto other projects.
    I'm not into selling .exe or .php bots or .php sites just yet. Just want to learn and then give a lot of them away for free (gpl, etc.). I'd be seeing what sells (.exe) then build a competing one and then give them away for free. That way, I snatch an established business' customers and make them my free members. I'll earn from ad displays. Then, I will build web versions so members can login to their free accounts and use the free web versions when on the road (like in train or plane) and away from their home computers where they got their .exe versions installed). I'm not into selling bots because I don't like customer baby sitting. Pi**es me off. Plus selling is hard. But giving away .exe for free is not. I'll earn from the ad displays. Likewise, I can give away free memberships for people to use the web versions of the bots and I can then get the opportunity to display ads on their member accounts. Make money that way. More people are likely to signup to a free membership site to make use of .php bots for free than to a paid membership site. And, I'll get the opportunity to display mine and my sponsor ads to thousands of people and make money from them indirectly. That is my aim. Attain more eye balls on mine and my sponsor ads. If I can't get in peoples' pockets through the front door then I'll try the back door.
    You guys can copy my ideas. I don't mind. Aslong as you guys contribute code snippets for my learning, I'm fine. I'm not too fussy or greedy. And that is why you guys will like me in the end. Especially, like my enthusiasm and my creativeness. Just watch how I use these php codes that will run an Android app. I know it sounds impossible but if only you saw things the direction I'm seeing things then you will laugh your head-off and say: "Why did I not think of this ?"! Oh hell! I might aswell reveal little here so you guys don't think I'm crazy.
    You see, smart fone market is big nowadays than computer market. Sooner or later, .exe computer software sales would take a heavy tumble and android app sales sky rocket. Nowadays they build .exe bots to automate the computer browser and I'm trying to build .php versions so you can run web bots from any computer. Tomorrow, I want my members to run android browser bots to run bots from their smart fones. But, do I have the time to learn both php and android programming ? No! So, is my dream to build bots for Android fones gonna go to waste ? No! I'll get into the market through the back door! No doubt you guys will say: "if you want to build computer app then learn php. But if you want to build Android app then learn Android SDK or whatever the hell it is. If you want to build both then learn both". But, I'm clever and will take a short cut in the beginning and won't learn Android programming. I'll learn php and dream of building an app that would cater for both industries (computer & smart fone). Now, you are rolling your eyes! And so, here's the big idea:
    I'll build php version of my bot which my members can use from any computer by logging into their accounts. I'll then use appsgeyser.com to build an android app for free. The app would be nothing but a browser or a window-frame (shell) that opens to my membership site. That way, members can use my web bots via their smart fones. I'll just have to pay someone at fiverr.com to convert my site to be suitable for mobile fones or I'll try grabbing a free tool (converter).
    Now, you, as my member, can now automate your Android fone (so to speak) to do internet tasks like link build, hunt for leads, etc.
    Interesting fellow, aren't I ? Just imagine what I could do if I had your programming skills! Have you thought of ways to make use of php & cURL for the Android market ? No ? And, you're a hard core php & cURL programmer. I'm just a kid down the block, who was born yesterday. And yet, I'm talking about automating Android fones with php & cURL!
    One of my project is: Poverty Reduction. Another is poverty eradication. And all with .exe and .php bots. And before you roll your eyes again. Don't forget I just showed you how an Android app can make use of your php code. And my idea and plan is reasonable. I've proven to you that I do not dream crap. Now, when I say I will build an app that will reduce poverty then I ain't talking crap. The plan is up my sleeve, right now. And it will slip out the very moment I finish my current php projects. Wait and see. Hold your breath. And, don't complain for this post becoming too long. It is taking you 15 mins to read it. But, it took me 3hrs to write and edit it and save the edit about 20 times!

    And no. I am not trying to talk you people into building my bots in full so I can just go and sell the php scripts. No. I try learning from you guys all the necessary functions that will be needed to achieve my goals. I don't want you guys building my .php bot 100% today where I contributed 0%. Because, if I do that, then I don't learn anything and tomorrow I'd be dependant on you again to build another. Dependant on you guys forever. I want my freedom. Independance. Not dependancy. Saying all this. I will depend on you guys at the beginning to show us beginners coding samples (snippets like Kicken showed) so we beginners can learn from your coding styles. Later-on, when we beginners have matured a-bit then I will fly away after making some php (and maybe .exe) contributions in this forum before I leave. Got to save the world from poverty remember! Can't be wastimg all my time online. I'll get the bot to do all that via the Samung Galaxy.
    And yes, I'm capable of building a .exe version of Senuke. Infact, I can build a bot that will open thousands of accounts at devshed and make new threads and then get each fake account to chat with each other on the newly built threads as if humans are engaging with each other. Yes, I'm capable of building spam bots and click fraud bots. But guess what ? I don't build trash. I'm an honest guy. I hate fraud. Any form. And, I hate hackers, spammers, spamwareand spyware (scumware) builders even more. Not interested in building game cheating bots either. Like I said, I don't like fraud. At-all. I got a conscious. I got dignity.

    PS - Don't forget to contribute code snippets in my threads. Do read my threads and wonder: "What is he upto now ? Let's check out. Might learn something from the old duffer!"
    Last edited by UniqueIdeaMan; October 16th, 2017 at 06:45 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by gw1500se
    It would also help to use the numerous debugging techniques given here before posting a question. The OP seems to me to be a touch bit lazy in the reading and learning department and expects someone here to repeat the same answer each time the same mistakes are made.
    No. Not lazy. If you read my above post then you'll take your words back double quick! I got my bucket full to be honest and I'm forgetting things like add the coding error. Just added it.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    DSmabismad,

    Thanks for the hint. I corrected this:

    mysqli_query($conn,"DELETE FROM users WHERE id='$val'");

    to this:

    mysqli_query($conn,"DELETE FROM users WHERE ids='$val'");

    And this code is working:

    PHP Code:

    <?php

    /*
    ERROR HANDLING
    */
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    error_reporting(E_ALL);
    mysqli_report(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);

    include 
    'config.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 ids, usernames, passwords, emails 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"]; "</td>";
        echo 
    "<td>"; echo $row["passwords"]; "</td>";
        echo 
    "<td>"; echo $row["emails"]; "</td>";
        echo 
    "<td>"; echo "<input type='submit' name='submit' value='delete selected'>""</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 ids='$val'");
        }
    ?>
           <script type="text/javascript">
           window.location.href=window.location.href;
           </script>
    <?php
    }
    ?>

    </body>
    </html>
    But, how come it's working since this is deprecated:

    @each


    And this also working:

    PHP Code:
    <?php

    /*
    ERROR HANDLING
    */
    declare(strict_types=1);
    ini_set('display_errors''1');
    ini_set('display_startup_errors''1');
    error_reporting(E_ALL);
    mysqli_report(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);

    include 
    'config.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>
    <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 
    $sql 
    "SELECT ids, usernames, passwords, emails FROM users";
    $result mysqli_query($conn,$sql);
    while(
    $row mysqli_fetch_array($result))
        {
            echo 
    "<tr>";
            echo 
    "<td>".$row['ids']."</td>";
            echo 
    "<td>".$row['usernames']."</td>";
            echo 
    "<td>".$row['passwords']."</td>";
            echo 
    "<td>".$row['emails']."</td>";
            echo 
    "<td><a href=delete2a.php?ids=".$row['ids'].">Delete</a></td>";
        }

    ?>
    </table>
    </body>
    </html>
    Also, why on the 1st code the concatenation is used while on the 2nd one not ?

    PHP Code:
    echo "<td>"; echo $row["usernames"]; "</td>"
    PHP Code:
    echo "<td>"; echo .$row["usernames"]; "</td>"
    Do you suggest I use the concatenator or not ? And, in which code (amonst the 2) should I use it and on which not ?

    @anyone:
    Any chance anyone can convert those 2 codes to use not deprecated stuffs so other beginners too can learn from your input ?
    Does the 2nd code have anything deprecated ?

    Thanks!
    Last edited by UniqueIdeaMan; October 16th, 2017 at 07:40 PM.

IMN logo majestic logo threadwatch logo seochat tools logo