I am using the MySQL table below. I would like to add a field called 'subcheck'
that will be a yes/no value determined by the HTML form input TYPE = CHECKBOX
. What "type" should I give this new field?
Thanks in advance,
John
`submission` (
`submissionid` int(11) unsigned NOT NULL auto_increment,
`loginid` int(11) NOT NULL,
`title` varchar(1000) NOT NULL,
`slug` varchar(1000) NOT NULL,
`url` varchar(1000) NOT NULL,
`displayurl` varchar(1000) NOT NULL,
`datesubmitted` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`submissionid`)
)
MySQL does have BOOL and BOOLEAN data types, but they are synonymous with INT(1). So this is the type you would use with the possible values 0,1, or NULL. 1 would be true (checked). 0 would be false.
MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.
ALTER TABLE users ADD bio VARCHAR(100) NOT NULL; Adding a boolean column with a default value: ALTER TABLE users ADD active BOOLEAN DEFAULT TRUE; MySQL offers extensive documentation on supported datatypes in their documentation.
You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.
You can use a TINYINT(1)
(BOOL/BOOLEAN is just an alias for TINYINT(1)
).
Another option is to store Y/N
in a CHAR(1)
.
I would recommend TINYINT(1)
as it would give you best portability options.
a boolean - 1 for yes, 0 for no.
(value of the checkbox will need to be 1 or 0 of course).
Much more portable than yes/no imo. efficient too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With