Page 1 of 1
$POST method with radio buttons?
Posted: Wed Apr 01, 2009 4:21 am
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 />
insert.php
Posted: Wed Apr 01, 2009 4:23 am
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>
Re: $POST method with radio buttons?
Posted: Wed Apr 01, 2009 3:22 pm
by CKEANEDesign
anybody?
Re: $POST method with radio buttons?
Posted: Wed Apr 01, 2009 4:46 pm
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.
Re: $POST method with radio buttons?
Posted: Wed Apr 01, 2009 5:43 pm
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.