消息系统中的大小写敏感问题



有人能告诉我这里出了什么问题吗?

my username is: System

我的收件箱里有2封邮件。1发送到System, 1发送到System

我可以删除System邮件,但是当我试图删除System消息时,它从我的代码中给我'not your message'错误。

下面是视图消息页面的删除代码:

$delmsg=$_GET['delete'];
$idcheck = mysql_query("SELECT * FROM `inbox` WHERE `id`='$delmsg'");
$idfetch = mysql_fetch_object($idcheck);

    if ($delmsg !=''){
      if ($idfetch->to != $username){
         $errormsg = "Error - This is not your message to delete. Returning to your inbox... ";
         echo "<meta http-equiv=Refresh content=1;url=messages.php>";
      }else{
mysql_query("DELETE FROM `inbox` WHERE `to`='$username' AND `id`='$delmsg'");
         $errormsg = "Message deleted. Returning to your inbox...";
         echo "<meta http-equiv=Refresh content=1;url=messages.php>";
}
}

,下面是发送消息页面的代码:

if(strip_tags($_POST['send'])){
    $recipient= $_POST['sendto'];
    $subjectmsg= $_POST['subject'];
    $msgfull= $_POST['messagetext'];
    $date = date('Y-m-d H:i:s');
      if (!$recipient){
        $errormsg=" You must enter a recipient or your recipient's username must contain 3 or more characters. ";
    }elseif ($msgfull =="" || !msgfull){
        $errormsg="You cannot send a blank message. Please type your message in the text area above.";
    }elseif ($recipient && $msgfull){
        $checker=mysql_query("SELECT * FROM `user` WHERE `username`='$recipient'");
        $checkrows=mysql_num_rows($checker);
          if ($checkrows =="0"){
              $errormsg="User does not exist. Please check your SEND TO field";

    }elseif (!$subjectmsg){
    mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`, `saved`, `subject`) VALUES 
                                     ('', '$recipient', '$username', '$msgfull', '$date', '0', '0', 'No Subject')");
                                     echo "<meta http-equiv=Refresh content=0;url=messages.php>";
    }else{
    mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`, `saved`, `subject`) VALUES 
                                     ('', '$recipient', '$username', '$msgfull', '$date', '0', '0', '$subjectmsg')");
                                     echo "<meta http-equiv=Refresh content=0;url=messages.php>";
    }}
}

USER表中的'username'和INBOX表中的'to'都被设置为latin, varchar(255)。

更改以下行:

if ($idfetch->to != $username){

:

if (strtolower($idfetch->to) !== strtolower($username)){

使用strtolower()在比较之前将数据库中的Name和Message名都转换为小写。还将(!=)更改为(!==),因为我们想要类型和值的绝对匹配。

这不是一个完美的解决方案,但它是一个不需要更改大量代码的选择。

最新更新