SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    germany
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing value from radio/checkbox to MySQL

    hi...i have this question. How do i pass a value from checkbox/radio buttons/drop down select menus to the database?I would appreciate help in which the solution should look similar to this "normal" way of passing a value from a form,i.e with isset$POST(got this example login/password form online,and i want to use this pattern as well for radio buttons etc.). Here is the code which works perfectly:

    PHP Code:
    Login:<input type="text" name="login" value="<?php echo (isset($_POST['login'])) ? $_POST['login'] : ""?>">
      * (min. 6 chars.) <br>
    Password:<input type="password" name="password" value="<?php echo (isset($_POST['password'])) ? $_POST['password'] : ""?>">
    example of the menus which i am using are(without the $POST value of course, since i dont know how to do it):
    HTML Code:
    <select name="nation">
                    <option value=""> -- Please Select -- 
                    <option value="AF">Afghanistan 
                    <option value="AL">Albania 
                    <option value="DZ">Algeria 
                    <option value="AS">American Samoa 
                    <option value="AD">Andorra 
                    <option value="AO">Angola 
                   
    etc....
    <input type="radio" name="gender" value="male">male 
    <input type="radio" name="gender" value="female">female
    thank you in advance. it will be a great help for me!
    cheers

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your referring to submit the form and putting the info selected into the db:

    PHP Code:

    if(isset($_POST['firstname']))
    {

    $firstname trim($_POST['firstname']);

    //connect to db
    $sql "INSERT INTO table (firstname) VALUES ('$firstname')";

    }

    <
    form method="post" action="">
    <
    input type="text" name="firstname">
    <
    input type="submit" name="SUBMIT" value="submit">
    </
    form
    Thats the example in the simpliest form

    Silly

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    germany
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no..i am talking about how to post values from a checkbox/selectmenu or radio button like normal values.
    u know what i mean?

  4. #4
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is what Silly's example would do Jeannie.
    Change "firstname" to "nation" and maybe you will understand better. Are you familiar with php at all?
    Troy


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
  •