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

Have a computer problem? Ask in our SUPPORT forum!

Receive Discounted Software

No bull. Want cheap discounts for common software products?
  • AntiVirus
  • Video editing tools
  • Web development tools
  • Registry Cleaners
  • Computer speed boosters!
Our editors get these products sent to us WEEKLY for review.

WE WANT TO PASS THESE DISCOUNTS ON TO YOU! (We honestly don't need them)

So whack your email in the box below and when we receive stuff we'll forward it to you! Its that simple.


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