Re: Search Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <001601c3c527$65521360$7a01a8c0@hweehwee>, hhwee@xxxxxxxxxxx 
says...
> Dear all,
> 
> i need help with my search query statement.. what is wrong with my code?
> 
> <snip>
>       $word = split(" ", $keyword);
>       $num_words = count($word);
>       $word_str = "";
>       $criteria = "";
> 
>       for ($i=0; $i<$num_words; $i++)
>       {
>           if ($i)
>              $word_str .= "and colName like '%".$word[$i]."%' ";
>           else
>              $word_str .= "colName like '%".$word[$i]."%' ";
>       }
> 
>       $word_str .= "and col2 = '$foo' ";
> 
>       $criteria .= "$word_str ";
>       $table .= "db_table";
> 
>       $query = "select * from ".$table." where ".$criteria;
> </snip>
> 
> when i try to echo $query, i get ---  select * from where
> 
> and so of course MySQL gives me an error 1064 near ' where '
> 
> what happened?
> 
> thanx thanx!
> 
> hwee

For a guess - $keyword and $table are set in another form and you have 
register_globals set to off. You need to use $_POST or $_GET depending on 
how the info is submitted.

You should also consider the case where $keyword or $table is submitted as 
an empty string.

Cheers
-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux