473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pass dropdown value to mysql database

250 100+
Could some one tell me how to pass drop down list value from php to mysql database?
Jan 23 '08 #1
3 9162
nathj
938 Expert 512MB
Could some one tell me how to pass drop down list value from php to mysql database?
Hi ghijk,

There are a number of options available to you. The most traditional of which is to have the drop down on a form. Then when the form is submitted - using the submit button PHP can pick up the value using the ID/Name of the drop down control.
FORM:
[html]
<form id="main_form" name="main_form" method="post" action="targeturl.php">
<select id="main_select" name="main_select">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
<input type="submit" id="main_submit" name="main_submit" value="submit" />
</form>
[/html]

TRAGETURL:
[php]
$lcSelectedValue = $_POST['main_select'] ;
// if you want to use this as a number then wrap it in intVal($_POST[...])
[/php]


After you have the value you can use PHP MySQL functions to update the database. There's a great article on this here on The Scripts.

Data Abstraction Layer

The alternative is to use an AJAX call which will pass the variables to JS which then sends them on to PHP and the rtrurned message is written to the screen - not needing a acomplete re-load but rather simply refreshing a small portion of the display.

Hopefully there's enough there to get you up and running.

Cheers
nathj
Jan 23 '08 #2
ghjk
250 100+
Hi ghijk,

There are a number of options available to you. The most traditional of which is to have the drop down on a form. Then when the form is submitted - using the submit button PHP can pick up the value using the ID/Name of the drop down control.
FORM:
[html]
<form id="main_form" name="main_form" method="post" action="targeturl.php">
<select id="main_select" name="main_select">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
<input type="submit" id="main_submit" name="main_submit" value="submit" />
</form>
[/html]

TRAGETURL:
[php]
$lcSelectedValue = $_POST['main_select'] ;
// if you want to use this as a number then wrap it in intVal($_POST[...])
[/php]


After you have the value you can use PHP MySQL functions to update the database. There's a great article on this here on The Scripts.

Data Abstraction Layer

The alternative is to use an AJAX call which will pass the variables to JS which then sends them on to PHP and the rtrurned message is written to the screen - not needing a acomplete re-load but rather simply refreshing a small portion of the display.

Hopefully there's enough there to get you up and running.

Cheers
nathj



Thank u very much. But still database not update. :(
Jan 23 '08 #3
nathj
938 Expert 512MB
Thank u very much. But still database not update. :(
Hi,

If you read and follow the article I referenced in my original post you will see exactly how to update the database. It's easy enough but I'm not going to repeat the article here.

Read the article, try it out and if you get stuck with a specifc post back with the code (using code tags) and I'll help out some more.

The next step is for you to help yourself.

Cheers
nathj
Jan 23 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
6
by: assgar | last post by:
Hi I am trying to get data from a mysql database with php. These dynamic rows may have multiple prices between 1 and 5. I would like to use a drop dropdown to display these prices and allow...
4
by: Panna | last post by:
Hey there I am using phpMyAdmin and MySQL to develop a dbase application. I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database....
8
by: bimeldip | last post by:
Hi, i would like to display the list of tables in a database in a drop down list then when user selects a table, the table will be dispalyed on the page. So far i've done this: <? $dbname =...
2
by: Trailer | last post by:
Hello guys, this is my first post here. I tried searching for the answer, but I found out pretty quickly that I wouldnt find the perfect answer. I am pretty new to programming, but Im taking a class...
1
flexsingh
by: flexsingh | last post by:
Hello there I have kinda got gotten myself into a sticky situation. I am trying to do something which seams too big to do in my head but I feel I kinda know how to do it. My problem is I have a...
7
by: microsoftboy | last post by:
Hi, Using the following selection criteria, I am able to list the data from mysql db, but I would like to provide the following options for users: Select All Data, Select None. I am not sure if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.