-3

I have the following code to write the name and score of a player into a highscore table. How can I write the 'name' in uppercase into the database?

if(isset($_GET['name']) && isset($_GET['score'])) {
$name = strip_tags(mysql_real_escape_string($_GET['name']));
$score = strip_tags(mysql_real_escape_string($_GET['score']));

$checkExist = mysql_query("SELECT `name`, `score` FROM `$tbl_name` WHERE `name` = '$name'");
$row = mysql_fetch_assoc($checkExist);

if (mysql_num_rows($checkExist) > 0){
    if ($score > $row['score']){
        $sql = mysql_query("UPDATE `$tbl_name` SET `score` = '$score' WHERE `name` = '$name'");
    } else {
        // ERROR MSG: Your new score is lower.(not updating the database)
    }
} else {
    $sql = mysql_query("INSERT INTO `$tbl_name` (`id`,`name`,`score`) VALUES ('','$name','$score');");
}
hansistr
  • 1
  • 2
  • 3
    [`strtoupper()`](http://php.net/manual/en/function.strtoupper.php) is one way. There is an SQL method though, but I rather you ["Google" that](http://www.google.com). – Funk Forty Niner Aug 08 '14 at 20:02

2 Answers2

3

$name = strtoupper(strip_tags(mysql_real_escape_string($_GET['name'])));

http://php.net/manual/en/function.strtoupper.php

Ethan Turk
  • 437
  • 4
  • 8
0

Either use strtoupper() in PHP, or UPPER() in MySQL: both do exactly the same, it's up to you.