Solved

checkbox problem.

Posted on 2009-07-01
10
294 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:designersx
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 75 total points
ID: 24754139
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
 
LVL 8

Expert Comment

by:lharrispv
ID: 24754235
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
 

Author Comment

by:designersx
ID: 24754373
gamebits: u r great thanks a lot
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 50 total points
ID: 24755272
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
 

Author Closing Comment

by:designersx
ID: 31598869
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
 
LVL 28

Expert Comment

by:gamebits
ID: 24756528
Than you should have accepted my solution vimalmaria was almost 2 hours late.
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 24764199
ya gamebits i accept this

i have given with some explanation that's all

good.
0
 
LVL 28

Expert Comment

by:gamebits
ID: 24764240
No offense vimalmaria I guess I just had a bad day, take care.
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 24769504
Hi,

Ok no issue on this,

sorry for the mistake.

See U

take care
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 24769512
Hi,

sorry once again
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php convert date format 3 21
write screen output to text file 21 45
ebay api to see some data about my customers 2 26
mysql date time 14 27
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now