SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert radio btn info into mysql

    I am Building a form to submit to mysql.

    Have radio buttons and want to insert value into column for the user.
    Code:
     
    <tr>
    <td align="right" style="vertical-align:top;"><p>Ethnicity</p></td>
    <td  style="vertical-align:top;">
    <input name="ethnicity[]" value="Caucasian" type="radio">Caucasian<br />
    <input name="ethnicity[]" value="AfricanAmerican" type="radio">African American<br />
    <input name="ethnicity[]" value="Hispanic" type="radio">Hispanic<br />
    <input name="ethnicity[]" value="PacificIslander" type="radio">Pacific Islander<br />
    <input name="ethnicity[]" value="AmericanIndian" type="radio">American Indian<br />
    <input name="ethnicity[]" value="Other" type="radio">Other <textarea name="newethnicityOther" rows="1" cols="30"></textarea>
    </td>
    </tr>
    I know how to insert baseic information however I don't know how to write for inserting into the database on submit.

    If there is an example please let me know.
    Thanks
    Tim

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the page that recives data you will have available such array:
    PHP Code:
    $_POST = array(
        
    "ethnicity" = array(
            
    => "One of values: Caucasian/AfricanAmerican/Hispanic etc",
        )
    ); 
    note that only value of selected radio is sent.

    now you can use $_POST array to insert values to DB.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I write it into the insert...

    Code:
    $sql = "INSERT INTO user SET
             userid = '$_POST[newpersonalemail]',
    	password = '$_POST[newpass]',
            firstname = '$_POST[newfirstname]',
    	middlename = '$_POST[newmiddlename]',
    	lastname = '$_POST[newlastname]',
    	ethnicity =  $_POST = array(
    							"ethnicity" = array(
    							0 => "One of values: Caucasian/AfricanAmerican/Hispanic etc",
    								)
    							);,
    			  ";
    Should the One of Values: be taken out?

  4. #4
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql = "INSERT INTO user SET
    userid = '$_POST[newpersonalemail]',
    password = '$_POST[newpass]',
    firstname = '$_POST[newfirstname]',
    middlename = '$_POST[newmiddlename]',
    lastname = '$_POST[newlastname]',
    ethnicity = '".join(",",$_POST["ethnicity"])."',
    ";


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
  •