在mysql和php中区分大小写

时间:2013-12-10 14:48:09

标签: php mysql

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

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

请帮助我用完了想法。

1 个答案:

答案 0 :(得分:0)

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

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