I’m making a form with radio buttons (see http://jsfiddle.net/mjmitche/3c6Mc/) and users are submitting data mostly through radio buttons. What “type” will the values for the radio buttons have to be/should they be in the mysql table?
The fields advocacy, drafting, interview etc will all be either “pass” or “fail” on the webform, so what do I do in the database?
CREATE TABLE `shoutbox`(
`id` int(5) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
`instructor` varchar(25) NOT NULL ,
`secretmessage` varchar(255) NOT NULL default '',
`advocacy` NOT NULL,
`drafting` NOT NULL,
`interview`
`letter`
`solicitor`
`barrister`
PRIMARY KEY (`id`)
);
Boolean
If I use a Boolean, do I set the values for Pass and Fail to 1 and 0?
<tr>
<td><label>Interview</label></td>
<td><input type="radio" name="interview" value="1" /> Pass</td>
<td><input type="radio" name="interview" value="0" /> Fail</td>
</tr>
with this mysql?
CREATE TABLE `shoutbox`(
`interview` BOOLEAN NOT NULL,
TinyINT
If I use a TinyInt, do I also set the value of Pass and Fail to 1 and 0?
<tr>
<td><label>Interview</label></td>
<td><input type="radio" name="interview" value="1" /> Pass</td>
<td><input type="radio" name="interview" value="0" /> Fail</td>
</tr>
CREATE TABLE `shoutbox`(
`interview` TINYINT NOT NULL,
ENUM
If I use enum, do I set the value to “pass” and “fail” and then use the same names in the database with enum?
<td><label>Interview</label></td>
<td><input type="radio" name="interview" value="pass" /> Pass</td>
<td><input type="radio" name="interview" value="fail" /> Fail</td>
</tr>
Mysql
CREATE TABLE `shoutbox`(
`interview` enum('pass', 'fail') NOT NULL,
ENUM may be behave unexpectedly if inserting integer values.
Example:
If you used ENUM, it would be best to validate the radio input value so that no empty or invalid strings are passed.
I recommend using an BOOLEAN or TINYINT and validating the radio input value by using intval();
php: