?
Solved

convert value to upper case and test against database using PHP

Posted on 2010-01-11
6
Medium Priority
?
210 Views
Last Modified: 2013-12-12
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
Comment
Question by:samic400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
ludofulop earned 1200 total points
ID: 26282179
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
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 800 total points
ID: 26282190
hi,

$str =$_REQUEST['input_value'];

$str = strtoupper($str);

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


"input_value" => value of ur text box . posted
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26282201
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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 15

Expert Comment

by:ludofulop
ID: 26282229
@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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26282711
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26293842
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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question