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