[thelist] SQL question
Tom Dell'Aringa
pixelmech at yahoo.com
Wed Jan 22 15:11:00 CST 2003
--- rudy <r937 at interlog.com> wrote:
> > > also, your variable $searchname contains the appropriate
> wildcards,
> > > right?
> >
> > Yes, it will be a first or last name of a man or a woman.
>
> okay, but if $searchname does not contain the appropriate wildcard
> characters for your database, you might as well use an equality
> test for an exact match instead of LIKE
>
> e.g. LIKE 'John%' will find both 'John' and 'Johnny'
>
> what i meant was, presumably you are appending the wildcards to
> whatever the
> user entered, before substituting the value of $searchname into the
> sql
Not sure I follow, I understand how the wildcard works, but I do want
an exact match, not a close match.
Now, using my SQL direct in mySQL works - here is my sample query:
SELECT
groom, groomf, bridef, bride, date, reguserID
FROM
reguser
WHERE
groom LIKE 'george'
OR groomf LIKE 'george'
OR bride LIKE 'george'
OR bridef LIKE 'george'
Works like a charm. However, in my page where I have this: (this
block is in an else clause where it runs if there is no field
specified by the user [ie, groom, groomf etc])
$result = @mysql_query(
"SELECT
groom, groomf, bridef, bride, date, reguserID
FROM
reguser
WHERE
groom LIKE '$searchname'
OR groomf LIKE '$searchname'
OR bride LIKE '$searchname'
OR bridef LIKE '$searchname'");
I get the following error:
You have an error in your SQL syntax near 'LIKE 'george'' at line 6
Which makes no sense. I copy that exact code, replace $searchname
with george and it works..any ideas?
=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list