Jump to content
IChaps

How might I use dropdown lists, and update a database table?

Recommended Posts

Hello.

 

I'd like to request a little guidance with regards forms and updating a database table please.

 

I've created a form which has a dropdown list.

 

I'd just like to enquire:-

 

1. How do I pass the selected result from the dropdown list to a variable? (at present I've written:- $user_gender = $_POST["profile_gender"] ;)

 

2. I'm unable to update the database table. The database opens and there's no errors reported. I'd just like to ask the following looks ok? $sql = "UPDATE registration_table SET Gender='$user_gender' WHERE Member_id='$userID'";

 

Thank You.

 

Share this post


Link to post
Share on other sites

Assuming the form was submitted properly, the value from the dropdown will be in one of the elements in $_POST or $_GET. You could assign it to a variable or use it directly.

 

You should use prepared statements for your queries. Here's the tutorial page for prepared statements:

http://www.w3schools.com/php/php_mysql_prepared_statements.asp

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

×