Jump to content

Radio Button Not Posting Value


lauralee

Recommended Posts

I have included two radio buttons, Individual and Business, in a form for submitting membership information into a database. But, it shows as "Array" instead of the value of whichever radio button is selected. What am I doing wrong here? I have the id and value of the array different from the name, which should pass the word "Individual", or the word "Business" into the 'Membership_type' field, but the word 'Array' shows up instead.//this is the part of the form that uses the radio button in order to select what type of membership it is</p><input type ="radio" name="Membership_type[]" id="Individual" value="Individual" />  <label for="Membership_type[]">Individual</label></p><input type ="radio" name="Membership_type[]" id="Business" value="Business" />  <label for="Membership_type[]">Business</label>//after the form is submitted using if (isset(..... the various form fields are posted $Membership_type = $_POST['Membership_type'];//here I want to check the information that has been submitted by the form before inserting into the databaseecho '<p>' . $Membership_type . '</p>';//once the information is viewed and is correct, the data is inserted into the database.$sql = 'INSERT INTO address_book SET Membership_type= "' . $_POST['Membership_type'] . '",

Link to comment
Share on other sites

Remove the square brackets from "Membership_type[]"By the way, your labels should target the id, not the name:<label for="Individual"><label for="Business">

Link to comment
Share on other sites

Just to clarify what Ingolme has correctly pointed out. Array notation (brackets) is appropriate if you expect to receive multiple values under the same name. You would then retrieve them by array index, e.g.:$_POST['Membership_type'][0]The mechanism of a radio button means that you will receive a single value per name, so array notation is not appropriate. You could still access your data in the first element of the array (as shown above) but it is silly to use an array when a scalar value is all you need.

Link to comment
Share on other sites

What an easy fix. I knew it was something simple that I was overlooking. Since I needed only one answer from whichever radio button was selected, I didn't need an array like with check boxes. I really appreciate your quick replies on my questions! Thanks, again!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...