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


Case sensitive recognition in mysql and php

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

问题是变量$username的区分大小写的特性没有被识别。例如,如果我有用户Lord,并且在数据库中注册为lord,它将无法识别用户名。在mysql中,我尝试用SELECT username, car, damage, location FROM garage 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){,然后它将回显消息This is not your car和一切都是因为区分大小写的问题。

请帮帮我,我没主意了。

好吧,我设法克服了这个问题:

  $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>";