473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Checkboxes

Okay, I've only been doing php/mysql for a few months and I admit to
being a little stumped on this one.

I have a form which posts updates to a mysql table. I'd like to use
checkboxes to show and update boolean type values. In Access it's very
simple to create a field of type Yes/No, bind a form to the table, and
bind a checkbox object to the Yes/No field. I am unable to find generic
examples of this in php/mysql.

1. What field type should I use in a mysql table?
2. When the php<html><form> loads the data from the selected record,
what is the generic syntax for initializing the check box?

Jul 17 '05 #1
4 7892
'bonehead <se*********@here.org> writes:
I have a form which posts updates to a mysql table. I'd like to use
checkboxes to show and update boolean type values. In Access it's very
simple to create a field of type Yes/No, bind a form to the table, and
bind a checkbox object to the Yes/No field. I am unable to find generic
examples of this in php/mysql.

1. What field type should I use in a mysql table?
MySQL has a BOOL type but it's just a synonym for TINYINT(1).
Another possibility would be ENUM.
2. When the php<html><form> loads the data from the selected record,
what is the generic syntax for initializing the check box?


Here's one way:

// Set the variable $foo from the database or from form data.
$checked = $foo ? "checked" : "";
echo "<input type=\"checkbox\" name=\"foo\" $checked>";

Or later if you're outside PHP:

<input type="checkbox" name="foo" <?php echo $checked?>>

Or you could omit the $checked variable:

<input type="checkbox" name="foo" <?php echo $foo ? "checked" : ""?>>

There are several ways to do this; the important thing is to print
the "checked" attribute if the boolean variable is on/true.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #2
"Michael Fuhr" <mf***@fuhr.org> wrote in message
news:3f**********@omega.dimensional.com...
'bonehead <se*********@here.org> writes:

$checked = $foo ? "checked" : "";


Although, in the newer implementations of HTML, that would be

$checked = $foo ? 'checked="true"' : '';

Christopher Finke
Jul 17 '05 #3
"Christopher Finke" <ch**************@hotmail.usenet.com> writes:
"Michael Fuhr" <mf***@fuhr.org> wrote in message
news:3f**********@omega.dimensional.com...
'bonehead <se*********@here.org> writes:

$checked = $foo ? "checked" : "";


Although, in the newer implementations of HTML, that would be

$checked = $foo ? 'checked="true"' : '';


Shouldn't that be 'checked="checked"'? That's what the XHTML 1.0
DTD appears to require, and using "true" causes XHTML 1.0 and 1.1
documents to fail validation at validator.w3.org.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #4
Michael Fuhr wrote:
Here's one way:

// Set the variable $foo from the database or from form data.
$checked = $foo ? "checked" : "";
echo "<input type=\"checkbox\" name=\"foo\" $checked>";

Or later if you're outside PHP:

<input type="checkbox" name="foo" <?php echo $checked?>>


Got it working...thanks. The exact syntax for the checked argument is
where I was getting stumped.

Meanwhile, I came up with another fairly trivial question. I'll post it
under the heading "Textarea Formatting".

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the...
8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
5
by: @(none) | last post by:
I have a page which is a set of CheckBoxes generated daily and thus the number of Checkboxes changes each day. What I want to do is allow the user to select one or more checkboxes and the push a...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
8
by: PeteOlcott | last post by:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_change_structure.html I would like to completely understand how GUI controls such as this one are constructed. In the...
7
by: viki1967 | last post by:
I need one function javascript that: 1) when I enter in this htm page I see enabled only checkbox of categories A, M and T; checkboxes of microcategories all disabled; 2-a) If I select the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.