PHP Dynamic Checkboxes

I noticed the lack of tutorials or articles when using checkboxes in a dynamic form, so I thought I’d post some code I used recently to manage deleting rows. The thing most people forget isthat the checkbox field name has to have a [] on the end as this tells PHP to use an array and not a normal variable to hold the information.
PHP

if ($_REQUEST["btnDelete"])
{
	foreach ($_REQUEST["chkDelete"] as $value) {
	     echo $value;
        }
}

HTML

d> "; echo " "; echo " "; echo " "; } ?>
Username
".$row[username]."

Related posts:

  1. How to Bootstrap PHP Code



5 Responses to “PHP Dynamic Checkboxes”

  1. E says:

    Thanks.
    It worked like this for me

    if ($_REQUEST["chkDelete"])
    {
    foreach ($_REQUEST["chkDelete"] as $value)
    {
    echo $value;
    }
    }

  2. Jamsi says:

    Whoops, thanks! Forgot a bracket :)

  3. Dodger says:

    Help me please!

    What table structure i must have?

    I have:

    `userid` varchar(255) NOT NULL,
    `username` varchar(255) NOT NULL,
    `visable` tinyint(1) NOT NULL default ’1′,

    and trying (my lines 28,29):

    echo ” “;
    echo ” “.$row[username].”";

    and having next error”

    Notice: Use of undefined constant visable – assumed ‘userid’ in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test-check-add.php on line 28

    Notice: Use of undefined constant username – assumed ‘username’ in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test-check-add.php on line 29

    I whant to change visable value from 1 to 0 if checkbox is not checked. Plz, help, i am newbie…

  4. Best places to play, best strategies to win. Player ratings & reviews of top online casinos & pokers with highest payouts & biggest bonuses.

  5. Frank says:

    Yep man, thanks,
    if ($_REQUEST["btnDelete"]) {
    .
    .
    .
    }
    Was what I need, otherwise it doesn’t show the correct value.
    All the best

Leave a Reply