Storing Dropdown option value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pavanesh2009
Forum Commoner
Posts: 30
Joined: Wed Jan 13, 2010 7:24 am

Storing Dropdown option value

Post by pavanesh2009 »

Hello Everyone!!
I have creted a dropdown having two option YES/No & in mysql db i have taken field type tinyint(1)
Here is the code:

HTML Page:
<td align=right>is_fertilised</td>
<td><select name= "is_fertilized" style="width: 120px;">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></td>

PHP code:
$sql1 = "INSERT INTO trees
(tree_id,is_fertilised,)
VALUES
('$_POST[tree_id]',
'$_POST[is_fertilized]'
)";

but in the db it inserting only 'o' value or some time '1' ? Please suggest how i can store Yes/No instead of 0 &1.Is it a good idea or i need to stick with tinyint itself.

Thanks in Advance!!
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Storing Dropdown option value

Post by aravona »

yes / no is a boolean. It is the same as 0 / 1 and on / off as well as true / false.

There are only 2 options for your yes / no so using tinyint is fine. Its only 2 options (yes / no) so tinyint (1/0) is fine as its just the corresponding value. Its the same thing just with numbers.

http://cnx.org/content/m19544/latest/
Post Reply