You are here: Re: HELP: PHP search query SQL error « PHP Programming Language « IT news, forums, messages
Re: HELP: PHP search query SQL error

Posted by Shelly on 07/28/06 21:28

"Bob Smith" <bsmith@sudleydeplacespam.com> wrote in message
news:Iqtyg.6367$oa1.820@news02.roc.ny...
> On 7/28/2006 2:51 PM, Frankie wrote:
>> I'm trying to run the following search query:
>>
>> $query =
>> sprintf ("SELECT itemNumber, thumbnailURL, title, description, price
>> FROM apparel,hats
>> WHERE apparel.title OR apparel.description OR hats.title OR
>> hats.description
>> LIKE '%s'",
>> $_POST['tfSearch']);
>>
>> but it returns this error:
>>
>> "Column: 'itemNumber' in field list is ambiguous"
>>
>> Both "apparel" and "hats" tables share the same columns specified in the
>> SELECT clause.
>>
>> What I'm I missing?
>
> Indeed it is ambiguous. To avoid this, use apparel.itemNumber or
> hats.itemNumber in the SELECT list. Repeat for the other columns.
>
> Also, to avoid an SQL injection attack, be sure to filter the input in
> $_POST[...] using a function appropriate to your SQL implementation.

If you have a lot of fields to select, another way is to write it as:

$query = sprintf ("SELECT a.itemNumber, thumbnailURL, title, description,
price
FROM apparel a, hats h
WHERE a.title OR a.description OR h.title OR h.description
LIKE '%s'", $_POST['tfSearch']);

or use h.itemNumber if that is the one you wanted.

Shelly

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация