2013-01-07 17 views
0

有人可以請告知這裏出了什麼問題嗎?郵件系統區分大小寫的問題

我的用戶名是:系統

在我的收件箱中,我有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表中這兩個「用戶名」和INBOX表中的'to'設置爲拉丁語,varchar(255),如果有幫助的話。

+4

[**立即停止使用'mysql_'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?您需要使用[* prepared statements *](http://j.mp/T9hLWi)來防止SQL注入,並使用[PDO](http://php.net/pdo)或[MySQLi](http:///php.net/mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – Kermit

+0

非常感謝您的建議。 – user1953045

回答

2

更改以下行:

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

到:

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

使用strtolower()轉換都在數據庫中的名稱和消息名稱比較之前爲小寫。還將(!=)更改爲(!==),因爲我們需要類型和值的絕對匹配。

這不是一個完美的解決方案,但它的一個選項沒有改變很多代碼。

+0

Thankyou。 我現在會改變,然後看看擺脫所有的mysql_functions,並開始閱讀一些教程... o_O 我沒有設計任何網站好4,5年,所以它的學習曲線重新> _ < – user1953045

+2

或者只是'strcasecmp($ idfetch-> to,$ username)== 0' – lupatus

相關問題