shorty3 Posted July 29, 2010 Share Posted July 29, 2010 right ive setup my own messaging feature on my website but it still allowes me to message myself if tried <? }else{ if($to == username){ ?> the whole code so you can get a better understanding <?php session_start(); include_once "includes/db_connect.php"; include_once "includes/functions.php"; logincheck(); $username=$_SESSION['username']; $fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); if ($fetch->texts < '1'){ echo "<font color=red>You don't have No Texts Left</font><br>"; }elseif($fetch->texts >= '1'){ ?> <body onLoad="goaway();"><? $towho=$_GET['fromper']; $oldmsg=$_GET['oldmsg']; $text=$_POST['text']; $subject=$_POST['subject']; $fsubject=$_GET['fsubject']; $info=mysql_fetch_object(mysql_query("SELECT rank FROM users WHERE username='$username'")); $goody = mysql_query("SELECT `inbox`, `date`, `from` FROM `messages` WHERE `id`='$rep'"); while($success = mysql_fetch_row($goody)){ $ini = $success[0]; $dateon = $success[1]; $fromper = $success[2]; } if(strip_tags($_POST['Send'])){ $text=strip_tags(addslashes($text)); $to = strip_tags(addslashes($_POST['to'])); $rep = $_GET['rep']; if((!$to)){ ?> <p class="style4">Please enter a username!</p> <span class="style4"> <? }else{ if(!$text){?> </span> <p class="style4">You cannot send a blank message!</p> <span class="style4"> <? }else{ if($to == username){ ?> </span> <p class="style4">You cannot send a message to yourself!</p> <span class="style4"> <? }else{ $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$to'"); $username_check = mysql_num_rows($sql_username_check); if ($username_check == 0){ ?> </span> <p class="style4">Invalid Username!</p> <span class="style4"> <? }else{ $date = gmdate('Y-m-d H:i:s'); $sql = mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`, `subject`) VALUES ('', '$to', '$username', '$text', '$date', '0', '$subject');") or die (mysql_error()); $sqll = mysql_query("UPDATE users SET texts = texts-1 WHERE username='$username'"); if(!$sql){ ?> </span> <p class="style4">There has been an error please contact an Admin !</p> <span class="style1"> <? }else{ echo "<table width=300 border=1 align=center cellpadding=0 cellspacing=0 bordercolor=#003300 class=thinline2> <tr> <td height=20 align=center bgcolor=#74CE59 scope=col><span class=style1>Your Message As Been Sent </span></td> </tr> </table>"; }}}}}} ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 right ive setup my own messaging feature on my website but it still allowes me to message myself if tried I have no clue what that means, what you are trying to accomplish, what's wrong, or what this script is supposed to do. What have you done to narrow the problem down? if($to == username){ ?> should be (and should have thrown and error): if($to == $username){ ?> Quote Link to comment Share on other sites More sharing options...
shorty3 Posted July 29, 2010 Author Share Posted July 29, 2010 i see what you mean <? }else{ if($to == $username){ ?> </span> <p class="style4">You cannot send a message to yourself!</p> That doesnt work Quote Link to comment Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 Ouput $to and $username to see what values they hold. Quote Link to comment Share on other sites More sharing options...
shorty3 Posted July 29, 2010 Author Share Posted July 29, 2010 right i have sorted this now but i can see what the problem was if my name was Megadust and i sent a message to megadust it would send me a message but if i put Megadust with a capital letter then it wouldnt let me send a message to my self how can i make it so it dont send a message to myself reguardless of captial letters or not. when i say my self i mean for every one who goes on my site not to allow it to send messages to them selfs Quote Link to comment Share on other sites More sharing options...
Maq Posted July 29, 2010 Share Posted July 29, 2010 if(strcasecmp($to, $username) == 0) { echo "same"; } else { echo "different"; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 29, 2010 Share Posted July 29, 2010 use strtoupper or lower to compare the two strings. a more effective way would be to use user ids. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.