• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

convert value to upper case and test against database using PHP

I need to take value from a search input text box, convert it to upper case, and test it against my mySQL DB to see if it exists.

How would I do this, using pHp, and what would the code look like?

Thanks in advance.
0
samic400
Asked:
samic400
  • 2
  • 2
  • 2
2 Solutions
 
ludofulopCommented:
user strtoupper to convert to uppercase, and LIKE in your query to find it in your db:
$query = "SELECT * FROM yourtable WHERE yourcolumn LIKE '%".(strtoupper($_POST['querystring']))."%'"
0
 
InsoftserviceCommented:
hi,

$str =$_REQUEST['input_value'];

$str = strtoupper($str);

select * from table where table.text = $str;


"input_value" => value of ur text box . posted
0
 
InsoftserviceCommented:
hi,

srry @ludofulop

it will fail  if in db its "ABCD"

and the i/p data is only "AB"


@samic400 have asked for if exist only so  we have to use  " = " symbol
Please correct if i am wrong.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ludofulopCommented:
@insoftservice, i presume that when talking about 'search input', it's about full text - kind of search...

if exact value is expected, then yes, the '=' is correct.

@samic400: anyway, don't forget to escape your user input, to prevent sql injections
0
 
Ray PaseurCommented:
Are the strings you are looking for case-sensitive at all?  There is little cost to using strtoupper() but it may not be necessary.  Better to know than assume that MySQL thinks "Cat" and "cat" and "CAT" are different.  You may find that they are all the same for MySQL.  Just a thought.
0
 
Ray PaseurCommented:
Just curious - did you test to see if the strings are case-sensitive?  I would love to see your test case and the results - it would be useful for the PAQ of this question.  Thanks, ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now