checkbox problem.

i am using checkbox in my form. what datatype i should take in mysql database. like i have a checkbox named sex having options male and female like below.

1) what data type i should take in mysql database
2) how can i retrieve the value using $_REQUEST.

<tr>
<td>Sex</td>
<td colspan="2"><input type="checkbox" name="sex" id="sex" value="male" /></td>
<td align="right">Female</td>
<td colspan="2"><input type="checkbox" name="sex" id="sex" value="female" /></td>
</tr>

please help me.
designersxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gamebitsCommented:
Radio button would be more appropriate (you have to choose between the two), checkboxes allows multiple choice.

The data type I used in MySQL when there is a definite choice is ENUM in this example the choices would be

'male','female' anything else would not be inserted.

to retrieve using REQUEST it would be like this

$sex = $_REQUEST['sex'];

but with your script (2 checkboxes with same name) this will cause an issue.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lharrispvCommented:
how about making the datatype in the DB a boolean.  Set the feild to female and if they answer male in the form set the boolean value in the DB to false?
0
designersxAuthor Commented:
gamebits: u r great thanks a lot
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Vimal DMSenior Software EngineerCommented:
Hi
For making gender details we must use only the option buttons,only then the multiple values won't be selected.
-------
Code
-------
<tr>
<td>Male</td>
<td colspan="2"><input name="rdgender" type="radio" value="1">
&nbsp;</td>
<td align="right">Female</td>
<td colspan="2"><input name="rdgender" type="radio" value="2">
&nbsp;</td>
</tr>

after setting of the option buttons like this

use the same method that others said
-----------------------------------------------
echo  $_REQUEST["rdgender"]
-----------------------------------------------
then see the final answer for this.
0
designersxAuthor Commented:
vimalmaria: and gamebits both have given the good solution but gamebits got the higher marks because i saw his comment and my problem was solved at that time.
0
gamebitsCommented:
Than you should have accepted my solution vimalmaria was almost 2 hours late.
0
Vimal DMSenior Software EngineerCommented:
ya gamebits i accept this

i have given with some explanation that's all

good.
0
gamebitsCommented:
No offense vimalmaria I guess I just had a bad day, take care.
0
Vimal DMSenior Software EngineerCommented:
Hi,

Ok no issue on this,

sorry for the mistake.

See U

take care
0
Vimal DMSenior Software EngineerCommented:
Hi,

sorry once again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.