mysql delete and update use checkboxes with submit buttons for multiple items

104 views Asked by At

I am new to the web developing world and this is my first time to post my questions at any forum.Please bare w/ me for having mistakes and insufficient knowledge, Here is my scenario: I am building a project that can update and delete an inputted data on my database, the thing is i need to use checkboxes to delete multiple items and click a submit button for them to be deleted, i decided to use if statements inside while loops for this matter.

Once the while loop receives the data it will echo/print them below is the code:

        mysql_connect('localhost', 'root', '123456') 
        or die("Unable to connect to MySQL");
        echo "Connected to MySQL<br>";

        mysql_select_db("Website Comment") 
        or die("Could not select examples"); 

        $results = mysql_query ("SELECT * FROM url");

        while($row = mysql_fetch_array($results))
        {
        echo('<input type="checkbox" value="$cb" /> </form>'); 
        echo $row[""].$row['url'];
        echo '<br/>';
        }

Now here lies my problem in deleting with multiple items using checkboxes, how do i connect the checkboxes with the submit button so that when they are ticked, they can be deleted.

        $del = mysql_query("DELETE FROM `url` WHERE 1");
        if ($cb = mysql_fetch_assoc($del))
        {
        echo('<input type="submit" name="Delete" value="Delete">');
        }

In my current code the checkboxes and submit buttons are disregarded the data is deleted even before ticking and clicking. I want to know if there are any alternatives for my problem or if there is a possible solution to my problem, I just want to know how to connect checkboxes with submit buttons so that when i do the update part it could be easy because i think it follows the same logic. Thank you for reading this and any help is appreciated.

1

There are 1 answers

0
Ram Sharma On

I suggest you that you should go through with this article. You are doing some very basic mistakes. Please go through with this link http://www.phpeasystep.com/mysql/8.html