473,503 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pass selected (drop-down) value to submit button

hannable80
2 New Member
Hi,

I have being doing some php code for the very first time using wordpress as a template, basicaly what i want the prog to do is get data from a drop down menu, which i have populated with data from a MSQL db. pass it to a button (on the same page) and it to run a SQL statemment and populate the data in a table.
What i am having problems with is to get the data to the botton where it will execute on the same page.
Code below:[php]<?php
$dbhost = 'it.test.com';
$dbuser = 'audit';
$dbpass = 'audit';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'WinAudi2';
mysql_select_db($dbname);
$result = mysql_query( "SELECT DISTINCT Computer FROM $dbname" ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=100 border=1>\n";
print "<select>";
while ($get_info = mysql_fetch_row($result)){
foreach ($get_info as $field)
print "<option>$field</option>\n";
}
print "</select></table>\n";
?>
</body>
</html>
[/php]

Please read the Posting Guidelines, its link is on the top of this forum. Especially the part about enclosing code within the appropriate code tags. - moderator
Feb 28 '08 #1
3 4873
ronverdonk
4,258 Recognized Expert Specialist
Welcome to TSDN!

What exactly is it you want or your problem?
You are already building a <select> drop down list, but I don't see a <form> or a submit button.
When you add that and after the selection has been submitted, what do you want to do with the passed data? And do you want to process it in the same script or in a new one. The previous is not clear to me.

If you have developed any more code to process the submitted data, show it here.

Ronald
Feb 28 '08 #2
hannable80
2 New Member
Welcome to TSDN!

What exactly is it you want or your problem?
You are already building a <select> drop down list, but I don't see a <form> or a submit button.
When you add that and after the selection has been submitted, what do you want to do with the passed data? And do you want to process it in the same script or in a new one. The previous is not clear to me.

If you have developed any more code to process the submitted data, show it here.

Ronald
Cheers

sorry about the pm
Expand|Select|Wrap|Line Numbers
  1.  <FORM>
  2. <INPUT type="button" value="Submit" name="GO"/>
  3. </FORM>
When i even this small bit of code in it throws a syntax error...
I have populated the drop down. I need to select a highlighted option in it and pass it as a var to a button. Then the button "onclick" will run a sql statement with the Value inserted from the drop down and refesh the page and dump out a table with the results of the statement...WoW that sounds alot but id say it would only be about 6 lines of code.

I have been reading up on it all day but i can't find a way to pass the high lighted data to a button!

As you can tell im more of a casual programmer SORRY!
Feb 28 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
Before you go any further, the following remarks on the code shown:

1. you use a database name 'WinAudi2' and a table 'WinAudi2'. That does not look correct to me.
2. your <option>'s have no values assigned to them.
3. your <select> list is not within a form, so where do you want to send the data to?
4. the <form> statement just has a submit attribute, but the form itself goes nowhere after hitting that submit
5. you want to pass the selection option value to a button. How do you intend to catch that value, via a submit to a script or using JavaScript?

I would propose the following:

1. assign values to the drop-down list, so they can be passed.
2. have the drop-down list AND the submit button within a <form>
3. after selecting an option from the drop-down, its value will be stored in the submit button. After hitting the submit button, the value of the drop-down is passed to the same script, where that value is inserted into the database and a 'dump-out' of the table is made? DUMP-OUT???

In order to prevent endless discussions here about what everybody means or wants, I'll take a shortcut and did some code work (only this time!). See the next (sanitized) code:[php]<script type="text/javascript">
function setButton(myvalue)
{
document.getElementById("myButton").value="Click here to \nupdate '"+myvalue+"' in database";
}
</script>
<?php
// prepare and connect MySQL actions
$dbhost = 'it.test.com';
$dbuser = 'audit';
$dbpass = 'audit';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die('Error connecting to mysql');
$dbname = 'WinAudi2';
mysql_select_db($dbname);

// Check to see if form was posted
if (isset($_POST['selectit'])) {
// if so, do what you plan to do
echo "Clicked and passed value: {$_POST['selectit']}<br>";
print "Update table in database<br>";
print "Show table<br>";
}
// form not posted: display selection box
else {
$result = mysql_query( "SELECT DISTINCT Computer FROM $dbname" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "<p>There are $num_rows records.</p>\n";
print "Select an option from the following list:\n";
print "<form method='POST' action='".$_SERVER['PHP_SELF']."'}>\n";
print "<select name='selectit' onChange='setButton(this.value);'> >\n";
while ($get_info = mysql_fetch_row($result)) {
foreach ($get_info as $field)
print "<option value='$field'>$field</option>\n";
}
print "</select>\n";
print "<p><input type='submit' value='&nbsp;&nbsp;&nbsp;' id='myButton'/></p>\n";
print "</form>";
}
?>[/php]Ronald
Feb 28 '08 #4

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

Similar topics

2
3229
by: Richard B. | last post by:
Hi, Currently designing/building my first class/template driven site. Inside a PHP form a list of article titles are displayed along with the first two lines of the article. When the user...
4
2797
by: Lisa | last post by:
I know this is supposed to be easy but I can't get this to work. I have a dropdown that pulls all the Projects (tp_title) available. All I want to do is get the ID (tp_id) of that record so I can...
1
2049
by: reneecccwest | last post by:
Hello, I'd like to pass the "levelbtn" value when I click the filter button, but there are also other submit form buttons. I defined as "document.testform.submit();" in the javascript, but I...
2
3479
by: Matt | last post by:
In the following code, I have 2 questions regarding submit button with image. 1) Does this code <input type="image" name="populate" src="populate.gif"> behave the same as an HTML submit button...
2
22264
by: a10392 | last post by:
Hi, I'am triyng to create a form where i have 2 comboBox and 2 textbox, when the selection changes on the first combo , the content of second also changes. i have to use onchange=form.submit() ...
0
2432
by: ab_j | last post by:
I have a user control that contains a dropdown which I want to use as a menu on multiple .aspx pages. Basically, all I am trying to do is pass the selected value of the dropdown in the user...
2
8053
by: Monty | last post by:
I use a SELECT dropdown as the nav interface for jumping to a chosen page number. When I setup up the SELECT element on the page, I want to show the user the current page number they are on, so, I...
1
2140
by: sdshah5 | last post by:
hi, i want to know how to pass selected value from dropdownlist of child page to a multiline textbox on the parent page. in my code it is giving me the "id" of the selected dropdown value in the...
1
1813
by: Shreenath A | last post by:
I am using two dropdown boxes in ASP. I want to pass the selected value of first dropdown to the QRY to fetch and display only those items which belongs to the first selected dropdown. I am using...
0
7192
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,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7445
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...
0
5559
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,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3158
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
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 ...
0
369
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...

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.