473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search engine with textbox, dynamic dropdown with MySql. Need Help

13 New Member
Hello everyone, this is my first post here so I will try to make it as clear as possible.

Firstly i have a database with a single table named "albums" with the following fields:
Expand|Select|Wrap|Line Numbers
  1. albumid    int(11)         
  2. genreid    varchar(30)     
  3. albumtitle    varchar(30)     
  4. albumauthor    varchar(30
  5. numberofsongs    int(11     
  6. price    int(11)
Then i have two php pages

Search.php :
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <center>
  4.  
  5. </br></br></br></br>
  6.  
  7. <img src="guitarlogo.jpg" alt="Music Database"/>
  8.  
  9. <form method="GET" action="Result.php">
  10.  
  11. <h2><b>Search Music Database:</b></h2>
  12.  
  13. <input type="text" name="mts" />
  14. <input type="submit" name="submit" value="Search" />
  15. </form>
  16.  
  17. <?php
  18. $connection = mysql_connect("localhost","root",""); 
  19. $fields = mysql_list_fields("ea09039", "albums", $connection); 
  20. $columns = mysql_num_fields($fields); 
  21. echo "<form action=Result.php method=POST>"; 
  22.  
  23. echo "<select name=Field>";
  24. for ($i = 0; $i < $columns; $i++) { 
  25. echo "<option value=$i>"; 
  26. echo mysql_field_name($fields, $i); 
  27. echo "</select></form>"; 
  28. ?>
  29.  
  30. </center>
  31.  
  32. </html>
  33.  
and Result.php :

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include("db.php");
  4.  
  5. $mts=$_GET["mts"];
  6. $Field=$_GET["Field"];
  7.  
  8.  
  9. $query="select * from albums where '$Field' like '%$mts%'";
  10.  
  11. $res2=mysql_query($query);
  12.  
  13. while($row=mysql_fetch_row($res2))
  14. {
  15. echo $row[2];
  16. echo " has author ";
  17. echo $row[3];
  18. echo " and costs ";
  19. echo $row[5];
  20. echo " Euro.";
  21. echo " And is from the genre ";
  22. echo $row[1];
  23. echo "<br/>";
  24. }
  25.  
  26. ?>
  27.  
This is as far as i have gotten with this, but i keep getting errors.
Please if someone can help I would be very thankful.
Dec 10 '10
12 7138
Xicer
13 New Member
Thank you Samishii23 the second part worked like a charm :D
Also thanks to everyone that contributed
Dec 10 '10 #11
Samishii23
246 New Member
Let me make a note about doing that. When you pass data like this there is a higher chance of someone finding out what your data is because they know something about your Database, though it is a bit far fetched, but the concept and possibility is there. Your better off using the #'s rather then the Field name itself.

You could use a field name array and do something like this:
Expand|Select|Wrap|Line Numbers
  1. $fields = array ('id','name','date');
  2. $Field = $fields[$_POST['Field']];
Dec 10 '10 #12
Xicer
13 New Member
Thank you for the information, i will try it out.
Dec 10 '10 #13

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

Similar topics

2
1523
by: vichet | last post by:
Hi All; Please help me with some problem i want VBSCRIPT to search something in only my own website give me code thank vichet
2
1473
by: sathyashrayan | last post by:
dear group, I have been working VC++ for some time. My company assigned me a task for an online dictionary search site similar to the onelook.com which I have to make it in php mysql. Since I never did any of the project in the search engine , can any one guide me to the above? I am really struggling to understand the following: When I enter a word in a text it searches the definition of the word from the web site but not the home page...
5
2495
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word was found was displayed with about 2 lines before and 2 lines behind the search word itself. Let us say you look for "peanut butter" an the word is found in a larger text about sandwiches, even when it is on the 40th line of the text you would get...
3
2657
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could search my portal (mySQL, PDF, Ms Word & others) 2. search engine that could search to few web sites specified by user/programmer
0
1022
by: JJ_377 | last post by:
I am trying to populate a two-column dropdown list from a populated datareader (dr) having two fields from the Categories table of the Northwind database: CategoryID and CategoryName. I've used this type of construction successfully with VB.NET (from which I am now transistioning...) and it has worked unfailingly with my dropdowns there. However, when I do this in C#, the result is only the CateogryID displaying in the dropdown. And...
3
1281
by: gaganlatha | last post by:
Hi, I want to create a search engine for my site. When i search a any keyword it should take me to that keyword. The keyword may be a country name, name, month etc. If this available in database it should take me there else if the keyword specified by the user is new it should store that keyword in database and when next time the user give that word it should display that result. Regards Latha
3
2054
by: d1156676 | last post by:
Hi I have a Dynamic dropdown reading in data from a MySql database, I need to refresh the dropdown when the database is updated without refreshing the whole page. I have had a go at trying to use a javascript and getelementbyid but with no sucess. Does any ones have any example or have any ideas on how i can do this. Any help will greatly appreciated
1
3573
by: miraan | last post by:
Hi, I have searched on the internet but can't find a way to disguise a long ugly php url such as www.domain.com/companies.php?id=543 into this: www.domain.com/companyname the folder "companyname" shouldnt really exist. There should be some instructions in .htaccess or something like that (not sure) to show www.domain.com/companies.php?id=543 instead but still keep www.domain.com/companyname in the address bar. I dont want to actually create a...
2
1236
by: nagendra802000 | last post by:
Hi All, I have created a search engine for MP3 with mysql database. Now I want to connect each search result with its respective info page which will consist with name of the artist, size, year, and so on. Dose anyone knows how to do it? I did created few static pages with all these info. But its impossible to create for thousands of MP3s. Please help me. Best,
0
8984
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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

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.