0

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

我的用户名是:系统

在我的收件箱中,我有 2 条消息。1 个被发送到System,另一个被发送到system

我可以删除系统邮件,但是当我尝试删除系统邮件时,我的代码中出现了“不是您的邮件”错误。

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

$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) 如果有帮助的话。

4

1 回答 1

2

更改以下行:

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

到:

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

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

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

于 2013-01-07T20:41:33.430 回答