Radio Button Variables to MySQL

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Radio Button Variables to MySQL

    Hello,

    I have a simple question, I am new to PHP Programming. I want to make a
    simple survey and insert the data into a MySQL Server. The data gets into
    the database fine, but I do not get the VALUE of the selected radio button.
    Instead what I get under the fields of the table is the NAME value. Example
    like:

    Table: gender_survey
    Field: GENDER Data: GENDER

    What I want is:

    Table: gender_survey
    Field: GENDER Data: MALE -OR- FEMALE depending on the radio button selected.

    -----------------------form.html-----------------------
    <form method="POST" action="collect.php">
    Gender: Male <input type="radio" value="MALE" name="Gender"> Female<input
    type="radio" value="FEMALE" name="Gender">
    <input type="submit" value="Submit" name="B1"><input type="reset"
    value="Reset" name="B2"
    </form>
    ---------------------------------------------------------
    -----------------------collect.php-----------------------
    Danke für Ihre Meinung!

    <?
    $username="USERNAME";
    $password="PASSWORD";
    $database="test";

    $Gender=array('MALE','FEMALE');
    $Gender=$_POST['Gender'];

    mysql_connect("10.33.39.252",$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";
    mysql_query($query);

    mysql_close();
    ?>
    -----------------------------------------------------------


    Danke Schön!


    Deutscher Guest

  2. Similar Questions and Discussions

    1. radio button
      i have 2 radio button and i want to set the 1st one is defaul <CFSET typeA = 'exempt'> <INPUT type='radio' name='typeA' value ='exempt'...
    2. Radio Button vSpacing
      Hello! I know this has to be really simple, but I can't seem to get it right. I have a flash survey that pulls the questions and radio buttons...
    3. Radio Button Validation
      :o Hello, I am using CFForm and CFInput to construct a rather simple form. However, the javascript that I am using in the onvalidate event of one of...
    4. Radio Button Help me please!
      Hi I need help quick! let me explain my problem: I¹ve made a form in flash with textfields and radio buttons. It submits the data from the...
    5. Radio button question
      Maybe a too simplistic solution, but which works fine, is to put textboxes over de buttons which contains the text you want the user to see. Make...
  3. #2

    Default Re: Radio Button Variables to MySQL

    *** Deutscher wrote/escribió (Mon, 06 Sep 2004 04:29:20 GMT):
    > Instead what I get under the fields of the table is the NAME value.
    You never use the variable. You insert a constant string:

    INSERT INTO geschlechts_umfragen VALUES ('Gender')
    > $Gender=array('MALE','FEMALE');
    What's this, the remainings of a test?
    > $Gender=$_POST['Gender'];
    > $query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";
    $query = "INSERT INTO geschlechts_umfragen VALUES ('" .
    mysql_escape_string($Gender) . "')";

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Questions sent to my mailbox will be billed ;-)
    --
    Alvaro G Vicario Guest

  4. #3

    Default Re: Radio Button Variables to MySQL

    Deutscher wrote:
    > Hello,
    >
    > I have a simple question, I am new to PHP Programming. I want to make a
    > simple survey and insert the data into a MySQL Server. The data gets into
    > the database fine, but I do not get the VALUE of the selected radio button.
    > Instead what I get under the fields of the table is the NAME value. Example
    > like:
    >
    > Table: gender_survey
    > Field: GENDER Data: GENDER
    >
    > What I want is:
    >
    > Table: gender_survey
    > Field: GENDER Data: MALE -OR- FEMALE depending on the radio button selected.
    >
    > -----------------------form.html-----------------------
    > <form method="POST" action="collect.php">
    > Gender: Male <input type="radio" value="MALE" name="Gender"> Female<input
    > type="radio" value="FEMALE" name="Gender">
    > <input type="submit" value="Submit" name="B1"><input type="reset"
    > value="Reset" name="B2"
    > </form>
    > ---------------------------------------------------------
    > -----------------------collect.php-----------------------
    > Danke für Ihre Meinung!
    >
    > <?
    > $username="USERNAME";
    > $password="PASSWORD";
    > $database="test";
    >
    > $Gender=array('MALE','FEMALE');
    > $Gender=$_POST['Gender'];
    >
    > mysql_connect("10.33.39.252",$username,$password);
    > @mysql_select_db($database) or die( "Unable to select database");
    >
    > $query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";
    > mysql_query($query);
    >
    > mysql_close();
    > ?>
    > -----------------------------------------------------------
    >
    >
    > Danke Schön!
    >
    >
    You may want to put a $ by gender in $query.. right?
    Breaker One Guest

  5. #4

    Default Re: Radio Button Variables to MySQL

    $query = "INSERT INTO geschlechts_umfragen VALUES ('$Gender')";

    --
    ZXSpectrum "Name The Game" - Can you guess the name of ZXSpectrum games,
    just by looking at a ingame picture? Well you can find out if you can (or
    not) at.... http:/ntg.docaj.net
    --


    RootShell Guest

  6. #5

    Default Radio Button Variables to MySQL

    Use "RadioGroup" to create and add Radio Buttons, and then retrieve the value of the selected Radio Button in the Group.
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139