php - mysql 和 php 中区分大小写的识别

标签 php mysql

我有以下文件:http://pastebin.ca/2495415

问题是变量 $username 不区分大小写。例如,如果我有用户 Lord 并在数据库中注册为 lord ,它将无法识别该用户名。 在mysql中,我尝试使用SELECT用户名,汽车,损坏,位置FROM车库WHERE username ='Lord'选择用户名Lord并且它有效,所以我猜mysql不是问题不过是PHP。 在 PHP 中有以下行

$carshit = mysql_query("SELECT username, car, damage, location FROM garage 
           WHERE id=".quote_smart($cartouse)."");

我非常有信心我检测到正确:)

我尝试过这样做:

$carshit = mysql_query("SELECT username, car, damage, location FROM garage 
WHERE id=".quote_smart($cartouse)." AND username='$username'");

并且

$carshit = mysql_query("SELECT username, car, damage, location FROM garage 
WHERE id=".quote_smart($cartouse)." AND username LIKE '$username'");

并且

$carshit = mysql_query("SELECT username, car, damage, location FROM garage 
WHERE username COLLATE UTF8_GENERAL_CI LIKE '%$username%'
id=".quote_smart($cartouse).""); 

此函数返回 mysql_fetch_row():提供的参数不是有效的 MySQL 结果资源。我认为这意味着 mysql_query 无效,可能无法识别 COLLATION..

也尝试过

$carshit = mysql_query("SELECT username, car, damage, location FROM garage 
           WHERE lower(username) = lower($username)") 
           AND id=".quote_smart($cartouse)."");

这是我重点关注的突出显示的代码

if($oooocstatuss!=Ready){
  $driverpanel=show;
  if($_POST['usecar']){
    $cartouse=strip_tags($_POST['cars']);
      if($cartouse==''){
        echo "<div class=\"hightct\">Error!</div>";
      }else{
        $carshit = mysql_query("SELECT username, car, damage, location 
                   FROM garage WHERE AND id=".quote_smart($cartouse)."");
        while ($carrinfo = mysql_fetch_row($carshit)) {
          $carowner = $carrinfo[0];
          $carrtype = $carrinfo[1];
          $carrdam = $carrinfo[2];
          $carrlocate = $carrinfo[3];
        }
        if($carowner!=$username){
          echo "<div id='theBox' class='failureBox'>This Is not your car!</div>";
        }else{ //does operations that should do. 

HTML 是这样的:

<form name="form6" method="get" action="main.php?page=oc....."> 
  <input name="id" value="170" type="hidden">
  <input name="username" value="Lord" type="hidden">
  <input name="page" value="oc" type="hidden">
  <input name="leave" value="driver" type="hidden">
  <input name="disoc" id="disoc" value="Leave OC" class="sub" type="submit">
</form>
<form id="form6" action="" method="post" name="form6">
            <td width="50%">
                <div align="center">
                    <select id="cars" name="cars">
                        <option value="3815">
                            Bugatti Veyron, 0% Damage
                        </option>
                    </select>
                </div>
            </td>

您选择以下字段和 if($carowner!=$username){ 然后它会回显消息 这不是你的车 一切都是因为区分大小写的问题。

请帮助我,我没有主意了。

最佳答案

好的,我成功地解决了这个问题:

  $carowner = strtolower($carrinfo[0]);
  $usernm = strtolower($username);
  $carrtype = $carrinfo[1];
  $carrdam = $carrinfo[2];
  $carrlocate = $carrinfo[3];
}
if($carowner!=$usernm){
  echo "<div id='theBox' class='failureBox'>This Is not your car!</div>";

关于php - mysql 和 php 中区分大小写的识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20497487/

相关文章:

php - 从表单插入多个值

php - 使用 CodeIgniter 事务?

mysql - mySQL 数据库位于 WordPress 站点的目录树中的什么位置?

php - 似乎无法连接到mysql、localhost?

php - MySQL 按所有字段的相关性进行搜索

PHP 和 MySQL - 从列中获取特定结果的数量

mysql - 查询上一行值并合并到当前行

mysql - MS Office 不再作为 BLOB 工作

mysql - 缓慢的 MySQL 查询正在填满我的磁盘空间

php - 使用 curl 和 ssl 发布数据时出错