Insert Into Database - Radio Buttons and dropdown menus

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > HTML, XML etc..

Insert Into Database - Radio Buttons and dropdown menus

HmmZ
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:
CODE
<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):
CODE
$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:
CODE
<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):
CODE
$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)

 

 

 


Reply

HmmZ
*BUMP*

Could someone please answer?>.<

Reply

Carsten
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
CODE
$SQL = "INSERT INTO go_logintable (birthDAY) VALUES ('{$birthDAY}')";

Reply

HmmZ
well, ill show you what I have right now in the reguser file:
CODE
<?php
include "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"
CODE
<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:
CODE
<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.

 

 

 


Reply

Carsten
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:
CODE
<?php
include "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:
CODE
<input name="gender" type="radio" value="1" />Male
<input name="gender" type="radio" value="2" />Female
Good luck with your script!

Reply

HmmZ
Thanks for the fast reply, hope it works =)

To understand it later on:
if ($_POST)
{
extract($_POST);

whats that for?

Reply

HmmZ
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)
)

Reply

Carsten
Replace the first part of your red table rows with this:
CODE
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.

Reply

HmmZ
Ok big thanks for the help Carsten

Ill be needing more help later maybe, I know little by little how to work, but sometimes I just bounce to some problems.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : insert database buttons dropdown menus

  1. Multiple Drop Down Menus W/ Submit Button - (6)
    I am building a page that will have 2 drop down menus and a submit button. The first menu will have
    one set of options, say colors (red, blue, green, yellow). The second menu will have another set of
    options, say sizes (small, medium, large). What I want to be able do is select a color and a size,
    click submit and have it go to the page for those options. So if a user picks 'Red' and
    'Small' and clicks submit they will be linked to page1.html. If they pick 'Blue' and
    'Large', they will be linked to page2.html, and so on. Any ideas how to ...
  2. Is Xml A Programming Language Or A Database Language? - (10)
  3. Form To Create Either A Mysql Or Msaccess Database - how do i do it (4)
    i was wondering if anyone here knew how to write a form that will create a MySQL database or a
    MSAccess database like on cpanel in the databases page, i want to know how to write a form like that
    (just the create database form). so any help would be great and if you knowq the code put it below
    thanks...
  4. Xhtml Strict Method For Submit/reset Buttons As An - (1)
    What's the proper way to handle submit and reset buttons? Using type submit and reset don't
    allow you to replace the default button with an image, using the type image doesn't allow a
    button to automatically act like a submit or reset....so far as I know. So How should I do this
    when I want to use a custom image as the button? Code will be best way to explain, thanks! ...
  5. Javascript Back , Forward Or Next Buttons Issue - (1)
    Okay webmasters, please put your wizard hats on and work your magic. I have a great little slide
    show that I am working on. I just about have it done, but I have a problem that is driving me
    nuts!!! The problem is my "back" button. Once the back button hits the first image and
    the user clicks back again, a javascript error occurs (it states: That my variable is not defined).
    I know that it is defined otherwise the back button would not work at all. The "next" button does
    not have this problem it will loop continously. I have been researching others slidesho...
  6. Dhtml Menu That Reads A Database - (7)
    I wanted to make a DHTML menu that read off a database, so it woud work with a menu system in
    PHP-nuke, called somarre patreballe, or something like that. Anybody can help me? I don't know
    much of anything about DHTML....
  7. Autofill Dropdown Removal - (3)
    When I go to a website and enter informaiton in a form my borwser saves this information, this also
    happens on my site. Now because I didn't do anything special I assume all my visitors have the
    same functionality, that is remember what they typed on a previous visit. Is there a way using some
    sort of language in my site to repress the browser wanthing to remember filled in form information?...
  8. Dropdown Menus Links - IDK how to make them link (3)
    Ok its a big problem to me, i need to make my drop down menus options link to a web page. I know i
    can do it with a button, and i can get that to work but i need/want to have it link as soon as the
    option is selected........How do i do that?...
  9. Substitute Form Button For An Image - homemade images in forms buttons (3)
    Hi, I have the next formular : CODE  <form method='post'
    action='index.php?mode=2&id=1'>                <input type='hidden'
    name='name' value='Canon Digital Ixus 700'/>                <input
    type='hidden' name='id' value='1'/>                <input
    type='hidden' name='qty' value='1'>                <input
    type='hidden' name='cost' value='40'>                <input
    type='submit' value='Add to ca...
  10. need help with drop down menus!! - (17)
    can any1 help me give a simple solution about mamking drop down menus with any programs or simple
    html coding. i want my site to look better than my friends ones but basic things like this are
    difficult for noobs like me to overcome...



Looking for insert, database, radio, buttons, dropdown, menus

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for insert, database, radio, buttons, dropdown, menus

*MORE FROM TRAP17.COM*
advertisement



Insert Into Database - Radio Buttons and dropdown menus



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE