473,769 Members | 4,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7926
'bonehead <se*********@he re.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.dimens ional.com...
'bonehead <se*********@he re.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
"Christophe r Finke" <ch************ **@hotmail.usen et.com> writes:
"Michael Fuhr" <mf***@fuhr.org > wrote in message
news:3f******** **@omega.dimens ional.com...
'bonehead <se*********@he re.org> writes:

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


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

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


Shouldn't that be 'checked="check ed"'? 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.or g.

--
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...thank s. 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
3965
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 checkboxes are picked up using $_POST and put into session variables. On page two there is another form which is simply a condensed version of the previous one (titles with no descriptions). The checkboxes are named the same on both forms. When...
8
2833
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 boxes and saving to the database at the end with the 'Submit' command button. Is it possible to save the changes as the checkboxes are clicked? I suppose I'd need to write some dynamic ASP event handling at the same time as creating the checkboxes......
8
2842
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 is my code line that creates each checkbox (the php variable get
5
5895
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 "Done" button and then have a script which uses a "for" loop to check the status of each box. The code I use for this is Sample checkbox HTML <P STYLE="margin-left: 1.5in"><INPUT TYPE=CHECKBOX NAME="CheckBox0"
6
2847
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++) checkboxes.checked=thestate } This works fine - but the problem is that it doesn't work with my
2
3195
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 user clicks on a certain button on the page, which is not in the grid, I want to be able to traverse through all the checkboxes in that column and see how many are checked. This is so that I can give them a confirmation dialog before I do an action...
10
5207
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. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
5
11279
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: for (int i = 0; i < 160; i++) { string checkbox = "checkBox" + i.toString(); (Cast)checkbox.enabled = false;
8
6040
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 ideal case I would like to see all of the source code for a complete working example of a ListBox of CheckBoxes.
7
2293
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 checkbox of macrocategory A, M and T checkboxes all disabled; 2-b) If I select the checkbox of macrocategory M, A and T checkboxes all disabled; 2-c) If I select the checkbox of macrocategory T, A and M checkboxes all disabled; 3) If I select the...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.