473,406 Members | 2,293 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,406 software developers and data experts.

How to use a value from a pick list?

I'd like to have a form that does the following:
User picks a site from a dropdown list from a MySQL db (that works -
code below, thanks to all those on the web who posted code for this).
Once the value is selected, a second query is run using the site as the
'where' clause and the results are displayed back to the user.

Any help for this mysql, php, htlm noob. I think once I get this bit,
I'll be able to move forward with more interesting and complex code.

TIA

Doug

ps - if this message shows up 3 times, my apologies but I've been having
trouble posting.

<html>
<body>
<?php

// connect to db
$db = mysql_connect("localhost");
mysql_select_db("test",$db);

// build query
$sitequery = "SELECT site from sitedata order by site";

// generate result set
$siteresult = mysql_query($sitequery);

// use results
echo "Select a site from the list below: <br><br><select name='site'>";
while($siterow = mysql_fetch_array($siteresult))
echo "<option
value='".$siterow["site"]."'>".$siterow["site"]."</option>";
echo "</select></td>";
?>

</body>
</html>
Jul 17 '05 #1
1 5167
Finally got the pieces to work together. For those of you who know what
you're doing, the following falls into the 'duh!' class. For anybody
else new to the game, I hope this helps.

Todo:
Disconnect the MySQL session.
Figure out a way to pass the db connection to the 2nd file rather than
reconnecting.
Convert everything to functions where it makes sense.
Play with other other form construction - embed php in html rather than
embedding html in php, figure out other methods to pass data between php
and html.

Dogu
Two files, both php.

First one returns a list of sites and launches the second form.
The second one uses the selected site name to return the password.

File 1:

<html>
<body>
<form action="getpw.php" method="get">

<?php

// connect to db
$db = mysql_connect("localhost");
mysql_select_db("test",$db);
$dbtbl = mysql_select_db("test",$db);

// build query
$sitequery = "SELECT site from sitedata order by site";

// generate result set
$siteresult = mysql_query($sitequery);

// use results
echo "Select a site from the list below: ";
echo "<br><br>";
echo "<select name='website'>";
while($siterow = mysql_fetch_array($siteresult))
echo "<option
value='".$siterow["site"]."'>".$siterow["site"]."</option>";
echo "</select></td>";

?>
<br>
<br>
<input type="submit" />
</form>
</body>
</html>

File 2 - getpw.php
The site you selected is <?php echo $_GET['website']; ?>.
<br>
<br>
The password is

<?php
// connect to db
$db = mysql_connect("localhost");
mysql_select_db("test",$db);

// build query
$pwquery = "SELECT password from sitedata where
site="."\"".$_GET['website']."\"";
// generate result set
$pwresult = mysql_query($pwquery);
$sitepw = mysql_data_seek($pwresult,0);
while($sitepw = mysql_fetch_array($pwresult))

echo $sitepw["password"];
echo "<br>";
echo "query is ".$pwquery;
?>
dogu wrote:
I'd like to have a form that does the following:
User picks a site from a dropdown list from a MySQL db (that works -
code below, thanks to all those on the web who posted code for this).
Once the value is selected, a second query is run using the site as the
'where' clause and the results are displayed back to the user.

Any help for this mysql, php, htlm noob. I think once I get this bit,
I'll be able to move forward with more interesting and complex code.

TIA

Doug

ps - if this message shows up 3 times, my apologies but I've been having
trouble posting.

<html>
<body>
<?php

// connect to db
$db = mysql_connect("localhost");
mysql_select_db("test",$db);

// build query
$sitequery = "SELECT site from sitedata order by site";

// generate result set
$siteresult = mysql_query($sitequery);

// use results
echo "Select a site from the list below: <br><br><select name='site'>";
while($siterow = mysql_fetch_array($siteresult))
echo "<option
value='".$siterow["site"]."'>".$siterow["site"]."</option>";
echo "</select></td>";
?>

</body>
</html>

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
4
by: Crystal | last post by:
Ok, I know this sounds weird, but it's really bugging me. I have a few list boxes on my form (basic pick a month, year, state stuff) and you can only choose one value. I need to be able to run a...
6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
1
by: Nikhil Patel | last post by:
Hi All, I am using a dll function that returns a two diamensional array containing BankNames and RoutingIds. I need to display BankNames and RoutingIds in two different comboboxes. When user...
2
by: Anand | last post by:
Hi All, I have a combobox with style as DropDown List. When I set the combobox.selectedIndex = 0, the first value is not showing up in the combobox and it is simply blank. Only if I...
10
by: Mark Winter | last post by:
Hello, I am wondering if someone could point me in the right direction to figure out how to create a dynamic form. I have been developing programs in perl and oracle and have recently switched...
5
by: bryan.com | last post by:
There must be a way. I'm making a selection from a drop-down list that had an ID number as the value and displays a text field. After submitting the data to the database I am sending an email and...
2
by: sparks | last post by:
I am trying to set the default value on a forms field to the filter that I am passing to the form. The filter works fine but the field comes up blank. So I put in a default value and it works...
5
by: davenet | last post by:
Hi, I'm new to Python and working on a school assignment. I have setup a dictionary where the keys point to an object. Each object has two member variables. I need to find the smallest value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
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...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...
0
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...

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.