Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2009, 04:51 AM
Registered User
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Mysql database to listbox need help

1.<html>
2. <head>
3. <title>List Box Form Data</title>
4. </head>
5. <body>

6. <p>Form data passed from the form</p>
7. <?php
8. require("./resources/globals.php") ;
9. $query="SELECT DISTINCT * FROM Garant GROUP BY Location";
10. $stmt= substr($query, 0, strlen($query)-4) ;

11.// Connect to the Database
12.$link=mysql_connect($location,$userName,$passwo rd) or die (mysql_error());
13.mysql_select_db($dbname) or die (mysql_error());
14.$result=mysql_query($query) or die (mysql_error());

15.// Select the Database
16.if (!mysql_select_db($dbname, $link)) {
17. DisplayErrMsg(sprintf("Error in selecting %s database", $dbname)) ;
18. DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error
19.($link))) ;
20. exit() ;
21.}

22.// Execute the Statement
23.if (!($result =mysql_query($query, $link))) {
24. DisplayErrMsg(sprintf("Error in executing %s stmt", $query)) ;
25. DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error
26.($link))) ;
27. exit() ;
28.}

29.echo"<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">';

30.echo '<select name="areasearch" onChange="submit();">';
31.while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
32.echo "<option value=$nt[Town]>$nt[Location]</option>";
33.}
34. echo"</select>";

35. echo" </form>";
36. echo $areasearch;

37. mysql_free_result($result) ;
38. ?>

39. </body>
40. </html>
The above code pulls the Location field records from database Garant. What I need to do is when a town is selected from the listbox, a new search thats finds all the places with that Location name. I can do the search stuff but how to get $areasearch valid?
Thanks for any help.
F





Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL database neil.abachi07 MySQL 13 October 8th, 2007 02:23 PM
MySql Database Problem surongama JSP Basics 0 October 16th, 2006 08:01 AM
Listbox entry in Database acces 2003 BramuS Classic ASP Databases 15 June 14th, 2005 03:02 PM
Listbox being poplutaed with Access database. gisenberg VB.NET 2002/2003 Basics 5 July 23rd, 2004 08:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.