-3

I'm using uppercase in the database but when I test the input type it doesn't work when I use lowercase.

I tried to change this with CSS:

text-transform: uppercase;

it still doesn't work, it works only when I use the caps lock.

I tried also the strtoupper (PHP) function.

My question is: How can I send the input as uppercase without using the caps lock?

I think it will work if I make a copy of the database with small letters but is there a simple option to fix this?

my php code:

<?php
require_once 'db_config.php';

if($_SERVER['REQUEST_METHOD'] == "POST") {
    $postcode = array();
    $result = mysql_query("SELECT postcode FROM postcode_check");
    while($row = mysql_fetch_assoc($result)){
        $postcode[] = $row['postcode'];
    }
    if(preg_match('/^[1-9][0-9]{3} ?[a-zA-Z]{2}$/', $_POST['postcode'])) {
        if(in_array($_POST['postcode'],$postcode)) {
            $winkel = "<a href='#' class='g-btn type_postcode' role='button'>winkel</a>";
            echo "FreshFoods is beschikbaar bij jou in de buurt. $winkel";
        } else {
            echo  'FreshFoods is nog niet beschikbaar bij u in de buurt.';
        }
    } else {
        echo 'Voer 4 cijfers en 2 letters in als postcode. Voorbeeld 1234AB';
    }
}
?>

html code

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="text" placeholder="1234AB" maxlength="6" autocomplete="off" name="postcode" class="small" />
<input type="submit" value="controleer" />
</form>
hzrcan
  • 69
  • 8
  • 1
    can you also post your code here. – Hardy Mathew Apr 28 '15 at 16:17
  • php: [strtoupper($string)](http://www.php.net/strtoupper); sql: [upper("string")](https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_upper); javascript: ["string".toUpperCase()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase). – Jonathan Kuhn Apr 28 '15 at 16:20
  • What's not working? Once you have the string on your server, you can do whatever you want with it, call `strtoupper` as you already know; use a MySQL function, etc. It's not clear what your problem is. – laurent Apr 28 '15 at 16:21
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 28 '15 at 16:21
  • when I use strtoupper($string); it show the text only with uppercase. It doesn't send the input as uppercase – hzrcan Apr 28 '15 at 16:29
  • I see no 'sending' of anything @hzrcan. What are you referring to? – Jay Blanchard Apr 28 '15 at 16:30
  • @JayBlanchard I have zip codes in the database with uppercases. when I fill 1234as as example it doesn't find the zip code. When I use the caps lock; 1234AS on the input; it works. My question is how can I make it possible to find the zip code also with lowercases. – hzrcan Apr 28 '15 at 16:38
  • do you have any CSS rule related to `class="small"` that would modify this? – Funk Forty Niner Apr 28 '15 at 16:38
  • @Fred-ii- on the small class I tried text-transform: uppercase; – hzrcan Apr 28 '15 at 16:40
  • Fill, or search? You can search in lowercase, but select in uppercase. See my edited answer. – Jay Blanchard Apr 28 '15 at 16:42
  • remove all CSS rules related to that input, there may be something in there related to `form` etc. you're also not assigning anything to a POST array, so it's hard to understand what you're wanting to do here. If the goal here is to search for something in your table, then you need to add a `WHERE` clause (with `LIKE` maybe) and assign a variable to a POST array. I.e.: `$search=$_POST['postcode'];` - Using `LIKE` will find it for any letter case. I think it's your preg_match that is causing problems. – Funk Forty Niner Apr 28 '15 at 16:46

2 Answers2

0

Use the UPPER() method in your MySQL query -

INSERT INTO `table` (`column`)
VALUES(UPPER('data'));

This will insert 'DATA' into the column. To select you select as UPPER()

SELECT UPPER(`postcode`)
FROM `table`
WHERE `postcode` = '1234as'
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
0

PHP's [strtoupper] should work

$str = strtoupper($str);

MySQL also provides String function UPPER() Perhaps share some code?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
daxeh
  • 1,083
  • 8
  • 12
  • thanks Jay for correcting my typos. it's way too late at night and its sign to stop trying to contribute. cheers – daxeh Apr 28 '15 at 16:37