Computing.Net > Forums > Web Development > User defined search criteria for DB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

User defined search criteria for DB

Reply to Message Icon

Name: drew22299
Date: May 15, 2007 at 02:34:05 Pacific
OS: xp sp2
CPU/Ram: 2,000 mhz 512mb
Product: n/a
Comment:

Can anyone show me in basic php or asp how to allow a user to enter keywords into a text field and have the database return entries with the keyword they typed in?

I know the SQL for it, but how do you define a variable that will store the keyword the user enters and how do you put it into the SQL query? Please help!

Drew,



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: May 15, 2007 at 09:19:41 Pacific
Reply:

Well, let's say you have a form with a field for the user to enter in the last name. We'll assume the name of the field is last_name.

In PHP on the page that receives the form input you can access the value of what was entered via $_POST['last_name']. So, just take that variable an put it into your query:

$query = "SELECT FROM table WHERE last_name LIKE '%$_POST['last_name']%'";

Then use that string to run your query.

Michael J


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: User defined search criteria for DB

best search engine for Shopping www.computing.net/answers/webdevel/best-search-engine-for-shopping/2497.html

Search Feature for HTML www.computing.net/answers/webdevel/search-feature-for-html/4021.html

Search engine for CMS?? www.computing.net/answers/webdevel/search-engine-for-cms/2808.html