【问题标题】:PHP / MySQL - Write and check UPPERCASE in databasePHP / MySQL - 在数据库中写入并检查大写
【发布时间】:2014-08-08 20:01:55
【问题描述】:

我有以下代码将玩家的姓名和分数写入高分表。如何将大写的“名称”写入数据库?

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');");
}

【问题讨论】:

标签: php mysql uppercase


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    在 PHP 中使用 strtoupper() 或在 MySQL 中使用 UPPER():两者的作用完全相同,由您自己决定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 2016-09-07
      • 2011-12-11
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      相关资源
      最近更新 更多