Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 540801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:16:40+00:00 2026-05-13T10:16:40+00:00

I am building a survey, in which participants use a html form to enter

  • 0

I am building a survey, in which participants use a html form to enter details.

For example:

What gender are you?    Male | Female 

The Male/Female option can be selected using a radio button.

However, I would like to store the answer in my database as an INT value, which is 0 for male and 1 for female. How do I write a query which represents that?

I have a rough idea which looks like this, but doesn’t seem to work:

$__g = Array('male' => '0', 'female' => '1');

And also, how do I insert the value into the database? I have this, but am unsure if it works (since I can’t get the representing part correct)

$sql = "INSERT INTO `onlinesurvey` 
(gender) VALUES ('".$__g[$_POST['gender']]."');

Many thanks for your help =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:16:41+00:00Added an answer on May 13, 2026 at 10:16 am

    How do I write a query which represents that?

    Why convert the string to an int? I think what you want to do here is use an enum column type to represent the range of possible values…

    And also, how do I insert the value into the database?

    If you use an enum, you would just insert the string literal value as the column value.


    EDITED:

    Here is some information on how the enum type works:
    http://dev.mysql.com/doc/refman/5.0/en/enum.html

    So your query would look like this:

    $sql = "INSERT INTO `onlinesurvey` (gender) VALUES ($_POST['gender']);
    

    EDITED:

    I haven’t seen your HTML, but make sure the select list looks something like this:

    <select name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
    </select>
    

    The critical piece of this is getting the option value attributes to be equal to the enum values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a generic survey engine where end users can generate and design their
I am building a survey application where users can create surveys on the fly.
I am building a Facebook survey, in which there are multiple questions per a
I am building an online survey system for which I wish to produce statistics.
I'm building a survey w/ Codeigniter, and it's getting cumbersomely long...so I want to
building a site which has content for each section. urls range from; /work/ /work/print/
Building on another SO question , how can one check whether two well-formed XML
I'm building a CLI survey app in Java that lets users answer multiple-choice questions.
I'm building my first real CI app. I have to build a survey system--If
Here's the scenario: I'm building a Wordpress plugin to manage some survey research that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.