$POST method with radio buttons?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
CKEANEDesign
Forum Newbie
Posts: 19
Joined: Thu Mar 26, 2009 8:04 am

$POST method with radio buttons?

Post by CKEANEDesign »

Hey. So I tried putting information into a form and one of the form elements is a radio button. When I use the POST method to insert it into MySQL Database, it comes up as the value name for the form object, (the radio is gender between male and female). So it will come out m or f instead of the written option name like "Male" or "Female."

What do I do differently?

Code: Select all

<!-- Gender Form --!>
<select name="gender">
<option value="na" selected>Gender</option>
<option value="m">Male</option>
<option value="f">Female</option>
</select><br /><br />
User avatar
CKEANEDesign
Forum Newbie
Posts: 19
Joined: Thu Mar 26, 2009 8:04 am

insert.php

Post by CKEANEDesign »

the insert.php page that the form action links to..

Code: Select all

<html>
<body>
 
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("Database1", $con);
 
$sql="INSERT INTO Accounts (FirstName, LastName, Email, Username, Password, Gender, DOBMonth, DOBDay, DOBYear, Country, State)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[username]','$_POST[password]','$_POST[gender]','$_POST[month]','$_POST[day]','$_POST[year]','$_POST[country]','$_POST[state]')";
 
if (mysql_query($sql,$con))
  {
  echo("Congratulations. You've successfully added a user into the database.");
  }
else
  {
  die('Error: ' . mysql_error());
  }
echo "Record added";
 
mysql_close($con)
?>
 
</body>
</html>
 
User avatar
CKEANEDesign
Forum Newbie
Posts: 19
Joined: Thu Mar 26, 2009 8:04 am

Re: $POST method with radio buttons?

Post by CKEANEDesign »

anybody?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $POST method with radio buttons?

Post by requinix »

CKEANEDesign wrote:When I use the POST method to insert it into MySQL Database, it comes up as the value name for the form object, (the radio is gender between male and female). So it will come out m or f instead of the written option name like "Male" or "Female."

What do I do differently?
Look at your HTML and just think for a second.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: $POST method with radio buttons?

Post by McInfo »

I don't understand the problem you are trying to describe.

Are you trying to insert "male" and "female" into your database instead of "m" and "f"?

Code: Select all

<select name="gender">
    <option value="na">Gender</option>
    <option value="male">Male</option>
    <option value="female">Female</option>
</select>
Or are you wanting to use radio buttons instead of a select box?

Code: Select all

<label><input type="radio" name="gender" value="m" /> Male</label>
<label><input type="radio" name="gender" value="f" /> Female</label>
<label><input type="radio" name="gender" value="na" /> No Comment</label>
Edit: This post was recovered from search engine cache.
Post Reply