0

i am maintaing jobs portal site, in this in search box when user search with single character as 'C' then i want to dislay 'C developer' or 'C programmer' or ' C/C++ Develoepr' like. But i am getting 'Customer service jobs' and some other jobs. I am using the following query.

$qry="select * from tbl_jobs where job_title LIKE 
'".$_REQUEST['job_title']."%' or job_title LIKE '%".$_REQUEST['job_title']."%' ";

This query not working properly. Please help me how to display c language related jobs when user searches single word as 'C''

venkyrao
  • 121
  • 12
  • 3
    can you give me the link to the site? The SQL injection possibilities just seem endless. Bobby tables is comming for you! – Pinoniq Feb 05 '15 at 11:11
  • i will convert this query to prepare statements. But the problem is search conditions – venkyrao Feb 05 '15 at 11:14
  • Logically, if you search for all jobs including "C" it will also find all jobs with words that have a "c" in it. A possible solution may be to make a case-sensitive search (See [this question](http://stackoverflow.com/questions/5629111/how-can-i-make-sql-case-sensitive-string-comparison-on-mysql) for more info). However, in this case I would just say your current search is logical and should not be changed to fit the "C" usecase. – Praxis Ashelin Feb 05 '15 at 11:22
  • the query seems ok, apart from the security, however it could be that the collation of the field/table is set to case sensitive. change it to some case insensitive collation as utf8_general_ci the last two letters stand for that case sensitive/insensitive – peterpeterson Feb 05 '15 at 11:26
  • i am not saying about case sensitive. I am saying that when i search with c i am getting some unwanted results(like customer, css, csn) . i want exactly c developer, c programmer, like that – venkyrao Feb 05 '15 at 11:26
  • @venkyrao, no you are not getting unwanted results, you get results that you asked you are looking for all records that contain character `C` in job_title, you can try to find 'C ' <- with space but then you won`t find C++ and C# – szapio Feb 05 '15 at 11:51

1 Answers1

-1

Try with:

$qry="select * from tbl_jobs where job_title LIKE 
'%".$_REQUEST['job_title']."%developer%' or job_title LIKE '%".$_REQUEST['job_title']."%programmer%' ";

That's the closest thing I can come up with.