FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Add search bar in my site





ncwdavid
Hey,
I want to make a search bar in my site. Well i have the search bar made and it posts to find.php. Now i need to no how to get that info from the database. I was thinking of doing this:
Code:

<?php
$item = $_POST['item'];
$sql = "SELECT item_name FROM sales WHERE item_name='$item'";
$resource = mysql_query($sql);
$row = mysql_fetch_array($resource);

and then just do a while() function and so on. But i want to know if lets say the person enters in "php for dummies" and there is something in the database called php & mysql for dummies. will that not come up because it is not an exact match. How can i get more results if there is not an exact match? thanks in advance.
hexkid
ncwdavid wrote:
How can i get more results if there is not an exact match?

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
DanielXP
Code:
<?php
$item = htmlspecialchars(addslashes($_POST['item']));
$resource = mysql_query("SELECT `item_name` FROM `sales` WHERE `item_name` LIKE '%$item%'");
$row = mysql_fetch_array($resource);


There you go i also added htmlspecialchars and addslashes to protect your database from SQL injections.
ncwdavid
DanielXP wrote:
Code:
<?php
$item = htmlspecialchars(addslashes($_POST['item']));
$resource = mysql_query("SELECT `item_name` FROM `sales` WHERE `item_name` LIKE '%$item%'");
$row = mysql_fetch_array($resource);


There you go i also added htmlspecialchars and addslashes to protect your database from SQL injections.


Thanks, i havent tried it yet but will soon.
Related topics
Search Your Web Site with Yahoo!
i suggested to put a search bar
web design and site optimisation tips
Firefox...what's the big deal? please enlighten me!
Publishing My web site to search engines?
getting search bar on your site?
Firefox Search Engine Bar
Free google site search.
install phpbb forum, set width... add to my site
Firefox Search Bar
how site look, and what to add?
~~total SEARCH ENGINE OPTIMIZATION for your site!~~
Search bar for threads and topics on this site
Search My FriHost Site
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.