Radio Buttons and Submit Questions [SOLVED]
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Radio Buttons and Submit Questions [SOLVED]
Hello everyone!
In the registration page of the game I am working on I have five races you can pick from and from those races - pick either male or female gender.
What I want the Registration Page to do
1. let you fill out username/password/etc (which is up and running)
2. use a raido button to pick your race/gender (which I also have but they aren't active aka they don't send info to the database)
3. when the submit button is hit on the register page it will send all data to the database (players info and race/gender choice)
I have the parts running on my local host but I don't know how to get it communicating with the database.
In the registration page of the game I am working on I have five races you can pick from and from those races - pick either male or female gender.
What I want the Registration Page to do
1. let you fill out username/password/etc (which is up and running)
2. use a raido button to pick your race/gender (which I also have but they aren't active aka they don't send info to the database)
3. when the submit button is hit on the register page it will send all data to the database (players info and race/gender choice)
I have the parts running on my local host but I don't know how to get it communicating with the database.
Last edited by RogueTomboy on Mon Jul 25, 2011 7:16 am, edited 1 time in total.
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Radio Buttons and Submit Questions
So, you do have the username/password registration working and going to the database right? You just need to know how to get the radio button working?
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Re: Radio Buttons and Submit Questions
Yeah, I can register with username/email/password etc. My 'pick a race' was a dropdown menu but I want to change it to radio buttons to pick the race. I assume that my male/female choices will both equal the race they chose since there is no difference other than what avatar they will have.
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
Re: Radio Buttons and Submit Questions
assuming i understand what your after. a group of radio buttons is defined by giving them all the same 'name' attribute.
to retrieve the information from the posted form, you access it just like any other variable, $_POST['gender']
registration form (radio buttons) :-
Each selection has its own reference ID (human = 0 etc)
then on the form processing you gather information like so
if i have missed the point to this question, apologies. If not hope it helps
Code: Select all
<input type ="radio" name="gender" value="0" checked="checked" /> - Male
<input type ="radio" name="gender" value="1" /> - Female
registration form (radio buttons) :-
Code: Select all
<input type ="radio" name="gender" value="0" checked="checked" /> - Male
<input type ="radio" name="gender" value="1" /> - Female
<input type ="radio" name="race" value="0" checked="checked" /> - Human
<input type ="radio" name="race" value="1" /> - Android
<input type ="radio" name="race" value="2" /> - Alien
<input type ="radio" name="race" value="3" /> - Slug
<input type ="radio" name="race" value="4" /> - Toadstool
then on the form processing you gather information like so
Code: Select all
$gender = $_POST['gender'];
$race = $_POST['race'];
New Site Coming Soon! Stay tuned
Re: Radio Buttons and Submit Questions
If you have PHP active, you can print down your POST information. If you have a dropdown menu ( which is not a radio group ), the dropdown menu will be in there the same as the NAME attribute of the menu. If you choose with radio buttons, you have to group them. If you have 3 options, each button`s NAME attribute will be the same.
<input type='"radio" name="race" value="human"/>
<input type='"radio" name="race" value="orc"/>
<input type='"radio" name="race" value="fairy"/>
Now, in the PHP you can access the radio value like this: $_POST['race'];
The value this way will be either human, orc or fairy. You can also choose a default value using this: checked="checked".
So, <input type='"radio" name="race" value="human" checked="checked"/> will be the default value.
<input type='"radio" name="race" value="human"/>
<input type='"radio" name="race" value="orc"/>
<input type='"radio" name="race" value="fairy"/>
Now, in the PHP you can access the radio value like this: $_POST['race'];
The value this way will be either human, orc or fairy. You can also choose a default value using this: checked="checked".
So, <input type='"radio" name="race" value="human" checked="checked"/> will be the default value.
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Re: Radio Buttons and Submit Questions
Okay, thanks guys! I'm going to go and try out what I've learned and let you know!
Okay I am very much a noob or I've just been up too long. I understand what you guys are saying but integrating it into what I already have written is...confusing me I think.
This is what I already have written:
This is the altered code provided by you guys:
Yes...so lost :S
Okay I am very much a noob or I've just been up too long. I understand what you guys are saying but integrating it into what I already have written is...confusing me I think.
This is what I already have written:
Code: Select all
<?php
include 'connect.php';
?>
<link href="register.css" rel="stylesheet" type="text/css" />
<div id='regstuff'>
<form method ="post" action="reguser.php">
Type Username Here: <input type="text" name="player" size="21"><br>
Type Password Here: <input type="text" name="password" size "15"><br>
ReType Password Again: <input type="text" name="pass2" size "15"><br>
Type Email Address: <input type="text" name="email" size "60"><br>
<input type="submit" value="submit">
</form>
</div>
<div id='regrace'>
<?php
print "<center><h3><font color='ffffff'>Pick Your Character</h3></center></font>";
print "<center>";
print "<table border='0' bordercolor='black' bgcolor='#000000'>";
print "<tr><td><img src='images/hymale.png'></td><td><img src='images/hyfem.png'></td><td><img src='images/konmale.png'></td><td><img src='images/konfem.png'></td></tr>";
print "<tr><td><center><input type='radio' name='race' value='1'><font color='ffffff'>Hybrid Male</center></td><td></font><center><input type='radio' name='race' value='1'><font color='ffffff'>Hybrid Female</center></font></td>
<td><center><input type='radio' name='race' value='4'/><font color='ffffff'>Konori Male</center></font></td><td><center><input type='radio' name='race' value='4'/><font color='ffffff'>Konori Female</center></font></td></tr>";
print "</table>";
print "</td></tr></table>";
print "</center>";
print "<center>";
print "<table border='0' bordercolor='black' bgcolor='#000000'>";
print "<tr><td><font color='ffffff'><center>Stats<br>Attack<br>Defense<br>Hit Points<br>Spell Points<br>Energy</td><td><font color='ffffff'><center><br>7<br>6<br>23<br>7<br>100</center></font></td>
<td><font color='ffffff'><center>Stats<br>Attack<br>Defense<br>Hit Points<br>Spell Points<br>Energy</td><td><font color='ffffff'><center><br>10<br>8<br>27<br>0<br>100</center></font></td></tr>";
print "</table>";
print "</td></tr></table>";
print "</center>";
print "<center>";
print "<table border='0' bordercolor='black' bgcolor='#000000'>";
print "<tr><td colospan='2'><font color='ffffff'>Hybrids are the offspring of a Human and Kamere.</font></td><td colospan='2'><font color='ffffff'>Konori are one of the original races to inhabit Neo.</font></td></tr>";
print "</table>";
print "</td></tr></table>";
print "</center>";
?>
</div>
Code: Select all
<input type ="radio" name="gender" value="0" checked="checked" /> Male
<input type ="radio" name="gender" value="1" /> Female
<input type ="radio" name="race" value="0" checked="checked" /> Human
<input type ="radio" name="race" value="1" /> Hybrid
<input type ="radio" name="race" value="2" /> Kamere
<input type ="radio" name="race" value="3" /> Rilon
<input type ="radio" name="race" value="4" /> Konori
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
Re: Radio Buttons and Submit Questions
Ok i think i see what your trying to achive. you are combining the race and gender into one selection.
That makes things abit more awkward.
Despite whether your selecting race and gender together or indevidually. You still need to give each option an indevidual reference.
currently you have both hybrids as value 1 and Konori as value 4.
make them all indevidual. male hybrid value 1, female 2, Konori male 3 etc etc.
when it comes to putting them into your database, you need to decide whether you are keeping gender and race seperate entities. If so, you need to run an if statement to declare the indevidual race and gender. ie...
and so on. and there you are setting each race and gender different values.
That makes things abit more awkward.
Despite whether your selecting race and gender together or indevidually. You still need to give each option an indevidual reference.
currently you have both hybrids as value 1 and Konori as value 4.
make them all indevidual. male hybrid value 1, female 2, Konori male 3 etc etc.
when it comes to putting them into your database, you need to decide whether you are keeping gender and race seperate entities. If so, you need to run an if statement to declare the indevidual race and gender. ie...
Code: Select all
if($_POST['race'] == 1)
{
$race = 1;
$gender = 1;
}
else if ($_POST['race'] == 2)
{
$race = 1;
$gender = 2;
}
New Site Coming Soon! Stay tuned
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Re: Radio Buttons and Submit Questions
I read that and it just confused me even more lol I'm sorry I am still rather intensely new when it comes to coding.
I have no idea if I'd need to make a Human Male entry in the database and then a Human Female in the database or if I just add Male/Female to Human like you would for Hp or Sp.
So...yeah lol.
/overwhelmed a little
I have no idea if I'd need to make a Human Male entry in the database and then a Human Female in the database or if I just add Male/Female to Human like you would for Hp or Sp.
So...yeah lol.
/overwhelmed a little
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Radio Buttons and Submit Questions
yes make a field in your DB for race and one for class.
Include all your registration into one forums
so
<form>
race radios
class radios
character name
password
email
</form
that way it sends all data once to the same page with one submit button
then on reguser
Include all your registration into one forums
so
<form>
race radios
class radios
character name
password
</form
that way it sends all data once to the same page with one submit button
Code: Select all
<form method ="post" action="reguser.php">
Type Username Here: <input type="text" name="player" size="21"><br>
Type Password Here: <input type="text" name="password" size "15"><br>
ReType Password Again: <input type="text" name="pass2" size "15"><br>
Type Email Address: <input type="text" name="email" size "60"><br>
<input type ="radio" name="gender" value="0" checked="checked" /> Male
<input type ="radio" name="gender" value="1" /> Female
<input type ="radio" name="race" value="0" checked="checked" /> Human
<input type ="radio" name="race" value="1" /> Hybrid
<input type ="radio" name="race" value="2" /> Kamere
<input type ="radio" name="race" value="3" /> Rilon
<input type ="radio" name="race" value="4" /> Konori
</form
Code: Select all
$player = $_POST['player'];
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$race = $_POST['race'];
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Re: Radio Buttons and Submit Questions
Thanks Halls, got it to work XD
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets