Reputation: 628
$va=($_GET['search']);
$search=$bd->execute("search","*","page_description LIKE '%$va%' or page_title LIKE '%$va%' limit 8 ");
$search is my query i.e select * from search where page_description LIKE '%$va%' or page_title LIKE '%$va%' limit 8
If the user search for domino's , it is going to save it in $va . but after that I am having a problem in my query , its shows me the error sometimes
fatal man: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's%' or page_title LIKE '%dunkin's%' limit 8' at line 1 Query Run :SELECT * FROM search WHERE page_description LIKE '%dunkin's%' or page_title LIKE '%dunkin's%' limit 8
but when i use this $va=mysql_real_escape_string($_GET['search']); Its shows me null result but i have dinkin' donuts in my table search So any one can tell me what I am doing wrong
Upvotes: 2
Views: 56
Reputation: 4927
Try that
$search=$bd->execute("search","*","page_description LIKE \'%$va%\' or page_title LIKE \'%$va%\' limit 8 ");
OR
$search=$bd->execute("search","*","page_description LIKE %'" + $va + "'% or page_title LIKE %'" + $va + "'% limit 8 ");
Upvotes: 1