I would like to run a query on my database to check if a postcode exists in the database.
The postcode is generally of the format
However it may be written as:
ba21 9xy (LOWERCASE)
BA219XY (NO SPACES)
I have currently got the following that deals with the case difference but can't figure out how to deal with spaces. Trim/RTrim/LTrim appears to only remove trailing and leading spaces.
$query="SELECT postcode FROM newBusiness WHERE UPPER(postcode) = UPPER('$postcode')";
Does the following look like a viable solution?
$query="SELECT postcode FROM newBusiness WHERE UPPER(REPLACE(postcode, ' ', '')) = UPPER(REPLACE('$postcode',' ',''))";
Thanks in advance