Forum Moderators: coopster
[edited by: eelixduppy at 3:08 am (utc) on June 21, 2007]
[edit reason] removed personal link - see charter [/edit]
There are a few problems with your syntax. The first is, you cannot put an array in a string like that. The second is, your LIKE syntax is incorrect. The third is, you are matching the string exactly; I'm not sure if this is what you want, but my guess is no. And the fourth is that you are not escaping your variables. So, try something like this:
if($_POST['col']=="Author"){
$q="SELECT * FROM `BookNook` WHERE `Author` LIKE '%".[url=http://www.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]($_POST[search])."%'"; }
else if($_POST['col']=="Title"){
$q="SELECT * FROM `BookNook` WHERE `Title` LIKE '%".mysql_real_escape_string($_POST[search])."%'"; }
We also have a thread in our library that may help: Developing MySQL Search Query [webmasterworld.com].
Good luck!
Code-
if($_POST['col']=="Author"){
$q="SELECT * FROM `BookNook` WHERE `Author` LIKE '%".mysql_real_escape_string($_POST[search])."%'"; }
else if($_POST['col']=="Title"){
$q="SELECT * FROM `BookNook` WHERE `Title` LIKE '%".mysql_real_escape_string($_POST[search])."%'"; }
Eror message-
Fatal error: Call to undefined function: mysql_real_escape_string() in /www/cgi/Books/search.php on line 43
Can you tell me what is wrong with it?