Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2012, 02:25 PM   PM User | #1
vineet
Regular Coder

 
Join Date: Jun 2008
Posts: 173
Thanks: 2
Thanked 9 Times in 9 Posts
vineet is an unknown quantity at this point
search query product name

hi all

First i want to match the search keyword with the product name in product table.

If the match is found then i want to fetch all the product details from product table for that product.

so i would like to know whether my code is fine or not.

can this be shortened

PHP Code:
<?
$searchword 
$_REQUEST['searchword'];
$qry "select product_name from product_table where product_name LIKE '%$searchword%'";
$result mysql_query($qry);
if(
mysql_num_rows($result) > 0)
{
    
$searchqry "select * from product_table where product_name LIKE '%$searchword%'";
    
$searchresult mysql_query($searchqry);
    while(
$searchrow mysql_fetch_array($searchresult))
    {
    
//echo product_details;
    
}
}    
?>
vineet
vineet is offline   Reply With Quote
Old 11-05-2012, 04:22 PM   PM User | #2
>ssp-cdr<
Regular Coder

 
Join Date: May 2007
Posts: 100
Thanks: 16
Thanked 11 Times in 11 Posts
>ssp-cdr< is an unknown quantity at this point
use addslashes() when putting user input into an SQL query or else the presence of an apostrophe in it can cause problems

$qry = "select product_name from product_table where product_name LIKE '%".addslashes($searchword)."%'";
__________________
The CodingForums Funny Images thread - http://www.codingforums.com/showthread.php?t=245405
>ssp-cdr< is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 PM.


Advertisement
Log in to turn off these ads.