消息系统的区分大小写问题

时间:2013-01-07 20:37:26

标签: php

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

我的用户名是:系统

在我的收件箱中,我有2封邮件。 1已发送至系统,另一个已发送至系统

我可以删除系统邮件,但当我尝试删除系统邮件时, 它给了我代码中的“不是你的消息”错误。

这是查看消息页面中的删除代码:

$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)。

1 个答案:

答案 0 :(得分:2)

更改以下行:

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

为:

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

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

这不是一个完美的解决方案,但它是一个选项而不会改变很多代码。