List Info

Thread: Checkbox empty values




Checkbox empty values
user name
2006-11-14 11:33:10
Hope someone can help.
This may be easy but I'm struggling.

I have a page, which has several checkboxes on it, which I'm
submitting
to a database. Each checkbox submits a value to a column in
the
database.
i.e
checkbox1 inserts into database column checkbox1.
checkbox2 inserts into database column checkbox2.
etc , this works fine, if the checkbox is checked the value
of 1 (set
in my form) is entered into the db.

What I would like to do is enter the value 0 into the
database if the
checkbox is not checked.

Any suggestions welcome 
thanks in advance


--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHPgooglegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---

Checkbox empty values
user name
2006-11-14 14:28:53
use if (!empty=$checkbox1){
//inserts into database column checkbox1.
} else {
//inserts 0 into database column checkbox1.
}

and so on
 ;
On 11/14/06, steveyork < stevenwhiteleyhotmail.com">stevenwhiteleyhotmail.com> wrote:

Hope someone can help.
This may be easy but I'm struggling.

I have a page, which has several checkboxes on it, which I'm submitting
to a database. Each checkbox submits a value to a column in the
database.
i.e
checkbox1 inserts into database column checkbox1.
checkbox2 inserts into database column checkbox2.
etc , this works fine, if the checkbox is checked the value of 1 (set
in my form) is entered into the db.

What I would like to do is enter the value 0 into the database if the
checkbox is not checked.

Any suggestions welcome
thanks in advance




--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHPgooglegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---

Checkbox empty values
user name
2006-11-14 14:54:55
Unfortunately when a form is submitted with checkboxes (or
radio
buttons) unchecked, those variables are not sent (or at
least
interpreted by PHP) to the server.  You get either
"on" or nothing.
I'm guessing it's because "off" is basically null,
and if a variable is
null then it's really not set anymore.

Anyway, a way to get around that would be to have a
pre-determined
number of checkboxes either in a hidden variable or on the
server's
action page.  So if you have 10 checkboxes numbered
checkbox[1],
checkbox[2], etc, and then a hidden variable named
"checkbox_count" and
set to 10, you could say:

<?php
  for($i = 1; $i <= count($_POST['checkbox_count']);
$i++)
  {
    if(isset($_POST['checkbox[$i]']))
    {
      // insert 1 into database
    } 
    else 
    {
      // insert 0 into database
    }
?>


--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHPgooglegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )