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 3 4877
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
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 - <FORM>
-
<INPUT type="button" value="Submit" name="GO"/>
-
</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!
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(myval ue)
{
document.getEle mentById("myBut ton").value="Cl ick 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='".$_SER VER['PHP_SELF']."'}>\n";
print "<select name='selectit' onChange='setBu tton(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=' &n bsp; ' id='myButton'/></p>\n";
print "</form>";
}
?>[/php]Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 clicks on the article title
the form with the list of article titles is replaced with the full text of
the article selected.
Since the article ID for...
|
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 get the
developer assigned to that project (tp_assigned_to). Then, when I get
the developer, I need that to be redirected to a second page.
...
|
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
don't think it is right.
-----------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
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 with image populate.gif?
When I click p1 or p2 button, it will post the page to process.asp.
2) When I check the checkbox, I want the image in...
|
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()
the problem is, i want to have a button to finish the selection and save all the data to a database, but if i have diferent forms, i will not get the...
| |
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 control to the main
..aspx page.
In an attempt to make it more clear on what I am talking about, here is
the order of events in page life cycle (from...
|
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 put "selected"
next to the page number, as shown below:
-------------------------------
<form name="pick" method="post" action="showit.php">...
|
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 text box.
|
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 AJAX to do the same. Please help to pass the value for the second dropdown through AJAX only.
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |