473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass dropdown value to mysql database

250 Contributor
Could some one tell me how to pass drop down list value from php to mysql database?
Jan 23 '08 #1
3 9194
nathj
938 Recognized Expert Contributor
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="targetu rl.php">
<select id="main_select " name="main_sele ct">
<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_subm it" value="submit" />
</form>
[/html]

TRAGETURL:
[php]
$lcSelectedValu e = $_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 Contributor
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="targetu rl.php">
<select id="main_select " name="main_sele ct">
<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_subm it" value="submit" />
</form>
[/html]

TRAGETURL:
[php]
$lcSelectedValu e = $_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 Recognized Expert Contributor
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
21603
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 server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or...
5
11876
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 dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned...
6
1553
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 the user to select the one that apply. I am having problems getting the dropdown to filter using the "if" statements. //This works if...
4
3423
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. The code for this is as follows: $sql3="SELECT ID, UploadDate FROM Telkom"; $result2=mysql_query($sql3); $options="";
8
7544
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 = 'mysql_dbname'; // Get records from database (). $sql = "show tables from $dbname"; $result=mysql_query($sql);
2
1228
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 in c-programming and I am also trying to learn php and mysql on the side. What I have done successfully is: Get a server with mysql and php....
1
2548
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 website and and users come in and book a court. There are three courts, and on the first page ill have up its a table which they choose which court...
7
2285
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 this is possiible. Any help would be greatly appreciated. Here's my code <h4>SEARCH</h4> <form action="<?php echo $_SERVER ?>" method =...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.