Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
I can't INSERT user submitted data from a drop down list into the MySQL database
Old 01-30-2010, 05:55 PM I can't INSERT user submitted data from a drop down list into the MySQL database
Super Talker

Posts: 101
Trades: 0
So I have this registration script:


The HTML:
HTML Code:
<form action="register.php" method="POST">
    <label>Username:</label> <input type="text" name="username" /><br />
    <label>Password:</label> <input type="text" name="password" /><br />

    <label>Gender:</label>
    <select name="gender">
      <optgroup label="genderset">
        <option value="Male">Male</option>
        <option value="Female">Female</option>
        <option value="Hermaphrodite">Hermaphrodite</option>
        <option value="Not Sure!!!">Not Sure!!!</option>
      </optgroup>
    </select><br />
<input type="submit" value="Register" />
</form>
The PHP/SQL:

PHP Code:
<?php

$username 
$_POST['username'];
$password $_POST['password'];
$gender $_POST['gender'];

mysql_query("INSERT INTO registration_info (username, password, gender) VALUES ('$username', '$password', '$gender')
"
)  

?>
The problem is, the username and password gets inserted into the
"registration_info" table just fine. But the Gender input from the
select drop down menu doesn't. Can some one tell me how to fix this,

P.S. I know this is an unsafe script as I am inserting form data directly into the database without validating it in any way first. That's because I am just learning PHP/SQL and want to get the basics down first. This script will never actually go online.
thanks.
Towhid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-30-2010, 06:03 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Have you printed the values to screen after submissions?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-30-2010, 06:33 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
Super Talker

Posts: 101
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Have you printed the values to screen after submissions?
I'm not sure what you mean, I know the gender input hasn't been submitted because when I enter the Select All command in mysql monitor : "SELECT * from registration_info" I can see that the username and password has been inputted but the gender column is empty. It's not Null but empty.
Towhid is offline
Reply With Quote
View Public Profile
 
Old 01-30-2010, 06:38 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
echo the variables to the browser instead of running the SQL.

It's debugging 101 rather than guessing where it is not working.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-30-2010, 06:43 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
Super Talker

Posts: 101
Trades: 0
I made a stupid mistake, the problem was I used:

$gender = $_POST['gender'];

when the name of my drop down list was actually "dropdown"

Now that I clanged it to

$gender = $_POST['dropdown'];

It inserts just fine.
Towhid is offline
Reply With Quote
View Public Profile
 
Old 01-30-2010, 06:57 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Easily spotted by echoing the POSTed form keys and values to the browser.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-31-2010, 07:57 PM Re: I can't INSERT user submitted data from a drop down list into the MySQL database
solvision's Avatar
Average Talker

Posts: 29
Name: Simon
Trades: 0
you might want to change the name back to gender, once you get a second dropdown or more your coding will begin to be harder to follow. Fine if its for yourself, but i've realised the value of using logical names, variables in my coding as well as documenting throughout the file.

One of my sites is now 2yrs old and in its 4th or 5th version, so sometimes tracking parts can take a while. Dont think "ill just do it later" cause you never will, unless you are really disciplined. When a page is finished and working correctly go back and explain the things that arent obvious
__________________
ZAM Howto - simple, straight forward answers on how to get started with a website.


Please login or register to view this content. Registration is FREE
solvision is offline
Reply With Quote
View Public Profile Visit solvision's homepage!
 
Reply     « Reply to I can't INSERT user submitted data from a drop down list into the MySQL database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25733 seconds with 12 queries