Check Boxes
Moderator: General Moderators
Check Boxes
Can someone give me an explanation on how to use Check Box's with PHP. Is it a switch? An Array? I am trying to have it so a user can delete a user specified number of items
It's neither a switch nor an array.
The checkbox HTML looks like this:
<input type="checkbox" name="mycheckboxname">
Now, when this checkbox is submitted via a form to a PHP script, one of two things will happen:
1) If the box IS checked, then the variable $mycheckboxname will exist. You can check for it's existance by using isset($mycheckboxname)
2) If the box has NOT been checked, then the variable $mycheckboxname will not exist at all.
Here is some code:
hope this helps
The checkbox HTML looks like this:
<input type="checkbox" name="mycheckboxname">
Now, when this checkbox is submitted via a form to a PHP script, one of two things will happen:
1) If the box IS checked, then the variable $mycheckboxname will exist. You can check for it's existance by using isset($mycheckboxname)
2) If the box has NOT been checked, then the variable $mycheckboxname will not exist at all.
Here is some code:
Code: Select all
<?php
if (isset($_POSTї'mycheckboxname'])
{
echo 'you checked the box';
}
else
{
echo 'you did not check the box';
}
?>
<form action="" method="post" name="form">
<input type="checkbox" name="check" checked><br>
<input type="submit" name="submit">
</form>- roninblade
- Forum Newbie
- Posts: 21
- Joined: Thu Jun 13, 2002 7:12 pm
you shouldnt quit on it just like that. using checkboxes in php is very easy, here's an example:
create your checkboxes like this <input type="checkbox" name="tobedeleted[]">
then delete the items like this...
i assumed there that you were using a database. i hope that helps.
create your checkboxes like this <input type="checkbox" name="tobedeleted[]">
then delete the items like this...
Code: Select all
<?php
$delete_string = implode(",", $tobedeleted);
$query = "delete from $your_table where $your_field IN($delete_string)";
@mysql_query($query);
?>