SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using radio buttons to insert data into DB?

    Hi

    I have figured out how to populate a drop-down selection box from a database and then allow the user to select an option - which is then reflected in the database.

    However, what I was wondering is how does this work for radio buttons?

    Suppose I simply want a use to select their gender using one of two radio buttons. What kind of code would I need to then update the database with their chosen option?

    Currently, I have:
    PHP Code:
    <TR VALIGN="middle"
        <
    TD>Have Children:</TD>
        <
    TD
        <
    INPUT TYPE="radio" name="Children" VALUE="No" alt="radio" />No 
        
    <INPUT TYPE="radio" name="Children" VALUE="Yes" />
        
    Yes </TD>
    </
    TR
    Thanks.

    Mak.

  2. #2
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what database engine and scrtiping/programming technologies are you using?
    -- JIM BOLLA
    Wanna play Halo 2? My XBOX Live gamertag: crowdozer

  3. #3
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Hi

    Sorry, I forgot to mention that I am using the regular combo. of PHP/MySQL.

    Thanks.

    Mak.

  4. #4
    SitePoint Wizard Goof's Avatar
    Join Date
    Feb 2001
    Location
    Pittsburgh, PA
    Posts
    1,154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Say I have this:
    Code:
    <input type="radio" name="myRadio" value="value1"> Something<br>
    <input type="radio" name="myRadio" value="value2"> Something Else<br>
    If a user submits this form and selects the radio button next to "Something" then the string "value1" will be passed in the myRadio variable. If instead they select the "Something Else" radio button then the string "value2" will be passed in the myRadio variable. So basically, it's treated very similar to the select box. Set up the radios with different values, then by reading the passed form variable you can figure out which radio button was selected.

    Hope that helps,
    Goof
    Nathan Rutman
    A slightly offbeat creative.

  5. #5
    SitePoint Addict mak-uk's Avatar
    Join Date
    Dec 2001
    Location
    Midlands, UK
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Yes, I get that. What I was wondering, however, is how then is the database updated?

    If for example the database has a field called 'myRadio', how do I assign 'value1' or 'value2' to it?

    Would it be:

    myRadio='$myRadio'

    ?

    Thanks.

    Mak.

  6. #6
    SitePoint Wizard Goof's Avatar
    Join Date
    Feb 2001
    Location
    Pittsburgh, PA
    Posts
    1,154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If PHP is as easy as it's supposed to be, I would think you could figure this out from your code to update the select box option. I'm an ASP guy, so I don't know. Your best bet for this would be to post in the PHP forum, not the database forums.

    Goof
    Nathan Rutman
    A slightly offbeat creative.


Bookmarks

Posting Permissions

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