Jump to content
xisto Community
Sign in to follow this  
HmmZ

Insert Into Database Radio Buttons and dropdown menus

Recommended Posts

I am currently working on a registration page but I can't figure out a few things, wich all basically have the same thing in common

Radio Button:
In the registration form i have a gender selection and I want to input that into the database, I currently have the following:

<input type="radio" name="gender" value="1">Male<input type="radio" name="gender" value="2">Female

In the registering file I put the following (edited for the question):
$SQL = "INSERT into go_logintable(gender ) VALUES ('$gender')";

I have no idea if thats the right way to go, so please give me some pointers.
____________________________________
Dropdown Menu:
In the registration form i also have a birthdate selection and I want to input that into the database, I currently have the following:
<select name="birthDAY"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>

In the registering file I put the following (edited for the question):
$SQL = "INSERT into go_logintable(birthDAY ) VALUES ('$bday')";

Also here, I have no idea if thats the right way to go, so please some pointers here.

____
Basically its inserting the selections in the database, and I have no idea how to do it, what I wrote above, were just logically wroten lines (logical to my opinion), but I need feedback on it. (Register Page)

Share this post


Link to post
Share on other sites

First, what is the table field you want to put your birthday data in? I suppose it is birthDAY (why the uppercases in day?). The variable where the birthday is stored also is named $birthDAY, because birthDAY is the name of the <select> form element.

To get a working piece of MySQL code, change your

$SQL = "INSERT INTO go_logintable (birthDAY) VALUES ('{$birthDAY}')";

Share this post


Link to post
Share on other sites

well, ill show you what I have right now in the reguser file:

<?phpinclude "connect.php";$password=$_POST['password'];$password2=$_POST['password2'];$username=$_POST['username'];$fullname=$_POST['fullname'];$gender=$_POST['gender'];$birthday=$_POST['birthday'];$birthmonth=$_POST['birthmonth'];$birthyear=$_POST['birthyear'];$country=$_POST['country'];$email=$_POST['email'];$email2=$_POST['email2'];if (!$password==$password2) {	print "Your Confirm Password didn't match the original password";}if (!$email==$email2) {	print "Your Confirm E-Mail didn't match the original E-Mail";}else {  $password=md5($password);  $SQL = "INSERT into s_logintable(username, password, fullname, gender, birthday, birthmonth, birthyear, country, email) VALUES ('$username','$password','$fullname','$gender','$birthday','$birthmonth','$birthyear','$country','$email')";   mysql_query($SQL);  print "registration successful";}?>

If thats the right way to do it, please say so, also, i am not sure about the registration page, with the radio buttons and the dropdownmenu
This is what Ive done with the dropdownmenu "birthday"
<select name="birthday" style="background-color: #000000;font size=10; color:#D80202; text-decoration: bold;" size="1" border="0"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value=27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select>

and this the radiobuttons part:
<input name="gender" type="radio" value="1"><font size="2"><b>Male<input name="gender" type="radio" value="2">Female

I dont know if the code in the registering file (process file) will automatically select the selected value (ie birthday=31, the insert into database code puts in the birthday field the value 31 automatically)

As ive said before, im not sure what im doing here.

Share this post


Link to post
Share on other sites

I improved your reguser file. I am pretty sure it will worked, but I haven't checked. I don't have much time to go into detail about what I changed, but if you really feel you need more comment and after you looked at the php manual for it you can ask me. Anyway, This is the result:

<?phpinclude "connect.php";if ($_POST){	extract($_POST);		if ($password != $password2)	{  echo "Your Confirm Password didn't match the original Password";	}	elseif ($email != $email2)	{  echo "Your Confirm Email didn't match the original Email";	}	else	{  $password = md5($password);  $sql = "INSERT INTO s_logintable (username, password, fullname, gender, birthday, birthmonth, birthyear, country, email)     VALUES ('{$username}', '{$password}', '{$fullname}', '{$gender}', '{$birthday}',  '{$birthmonth}',  '{$birthyear}', '{$country}', '{$email}')");  if (mysql_query($sql))  {  	echo "Registration successful";  }  else  {  	echo "Something went wrong";  }	}}?>
The html for your dropdown box seems correct, it could need some cleaning though. Your radiobuttons part was also correct, though this is more valid:
<input name="gender" type="radio" value="1" />Male<input name="gender" type="radio" value="2" />Female
Good luck with your script!

Share this post


Link to post
Share on other sites

Just another quick question

 

Of course I need to create a table for the database and im unsure what the table needs (the ones i am not sure of are made red-colored)

 

CREATE TABLE go_logintable (

ID int(10) NOT NULL auto_increment,

username varchar(20) NOT NULL unique '',

password varchar(20) NOT NULL default '',

fullname varchar(40) NOT NULL default",

gender bit NOT NULL default",

birthday datetime NOT NULL default",

birthmonth datetime NOT NULL default",

birthyear datetime NOT NULL default",

country varchar(25) NOT NULL default",

email varchar(50) NOT NULL default",

PRIMARY KEY (ID)

)

Share this post


Link to post
Share on other sites

Replace the first part of your red table rows with this:

gender smallint(1) NOT NULL default,birthday smallint(2) NOT NULL default,birthmonth smallint(2) NOT NULL default,birthyear smallint(4) NOT NULL default,
Also, I would recommend to remove your double quotes in there.

if($_POST) checks whether or not a form has been submitted to your registration page. When you submit your form, an array is created called $_POST. This array contains all your form values, like $_POST['password'].

extract($_POST) extracts all array keys as values. This means that $_POST['password'] becomes $password.

Share this post


Link to post
Share on other sites

Ok big thanks for the help CarstenIll be needing more help later maybe, I know little by little how to work, but sometimes I just bounce to some problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.