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

How to display information from database using value selected in listbox

4
I want to display information when value in listbox selected.

Below is my code:-

This code to get value option in listbox
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $query = "select courseTitle from training where startDate > NOW() ";
  3. $result = mysql_query($query);
  4. print "<SELECT name=item>";
  5. while ($line = mysql_fetch_array($result))
  6. {
  7. foreach ($line as $value)
  8. {
  9. print "<OPTION value='$value'";
  10. }
  11. print ">$value</OPTION>";
  12. }
  13.  
  14. mysql_close($link);
  15. print "</SELECT>";    
  16. ?>
This code to display information from database when select value in listbox
Expand|Select|Wrap|Line Numbers
  1. <?
  2. if (isset($_GET['item']))
  3. {
  4.  
  5. $query=mysql_query ("SELECT training_id from training where courseTitle='$item' "); 
  6.  
  7.  
  8. while( $row = mysql_fetch_array($query) {
  9.  
  10.                $training_id=$row['training_id'];
  11.  
  12. echo $row['training_id'];
  13.  
  14. }
  15. }
  16.  
  17. ?>
Anyone can solve my problem? Thanks.
Apr 12 '10 #1
7 6932
Atli
5,058 Expert 4TB
Hey.

The $item variable you use in your query has not been defined. You need to fetch the variable from the $_GET array before you can use it. (In most cases, anyways.)
Apr 12 '10 #2
ieda
4
@Atli
can u give me an example how to use $_GET array for my coding so that i can implement in my code above..really appreciate!
Apr 12 '10 #3
Atli
5,058 Expert 4TB
You fetch an array element into a variable like so:
Expand|Select|Wrap|Line Numbers
  1. $variable = $array['element'];
The $_GET array works just like a normal array.

See the manual for more details:
- PHP: $_GET - Manual
- PHP: Arrays - Manual
Apr 12 '10 #4
ieda
4
@Atli
Thanks atli..i will try implement it.
Apr 12 '10 #5
Expand|Select|Wrap|Line Numbers
  1. $query=mysql_query ("SELECT training_id from training where courseTitle='{$_GET['item']}' ");  
Should do the trick.
Apr 13 '10 #6
Atli
5,058 Expert 4TB
@NettSIte
You should never put $_GET or$_POST variables directly into a query. Not unless you want your database to be hacked.

Imagine if the value of $_GET['item'] were:
Expand|Select|Wrap|Line Numbers
  1. ' OR 1='1
Or, even worse:
Expand|Select|Wrap|Line Numbers
  1. '; DROP TABLE training;--
You should always run your variables through mysql_real_escape_string before putting them into a query.

See SQL Inection for more details on why this is necessary.
Apr 14 '10 #7
@Atli
You should always run your variables through mysql_real_escape_string before putting them into a query.

True.
Apr 14 '10 #8

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

Similar topics

8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
2
by: baret bonden | last post by:
Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes ..I' m able to display the chosen item on it's form...
7
by: deepagulati | last post by:
Hi, I need an urgent help from you. When we dynamically genrate any list box (Select Box) it shows one default value as selected. Is there any way that we can deselect that value. I...
0
by: sthomas1 | last post by:
I am using vb studio 2005, I wish to dispay field1 and field2 and field3 from database view using text box multilines, how do you bind more then one field item? do you use custom binding and how ? If...
2
by: j.m.osterman | last post by:
I haven't found exactly what I've been trying to do. All I am trying to do for now is just display usernames from Active Directory into a ListBox control on a page. I have found some code...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
4
by: copewithit | last post by:
Hi all, I'm trying to modify a record (in this case the name associated with the record) to a new name selected by the user in a combo box. Right now I have Single Form with a subform in datasheet...
9
by: Ajinkya | last post by:
Hello friends ! , I am very new to java script.If anyone can help me then I will be very very thankful to his/her. I am using php and mysql in my project and I have one textarea and one...
5
by: boss1 | last post by:
hi all, i have a problem with loop in select statement.i m using code : <select name = "s" size = "1" > <option selected>P-Code</option> <option...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...
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
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,...

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.