send message if user is in the database, reject if not
<pre><code>if (isset($submit)) {
  $getusers = mysql_query("SELECT * FROM register");
  while($getrows = mysql_fetch_array($getusers)) {
    $users = $getrows['username'];
    if ($touser == $users) {
      echo "$users";
      $send = $_GET['send'];
      if ($send == $one) {
        $query = mysql_query(
                   "INSERT INTO mailtbl VALUES 
                    (
                      '', '$touser', '$fromuser', '$subject', 
                      '$message', '0', '0', '1', '$date', '$rand'
                    )"
                 );
        $query2 = mysql_query(
                    "INSERT INTO mailtbl_admin VALUES 
                     (
                        '', '$touser', '$fromuser', '$subject', 
                        '$message', '0', '0', '1', '$date', '$rand'
                     )"
                  ); 
        $echo = "Message successfully sent."; 
      }
    } else {
      $echo = "There is no such user with the name of '$touser'";
    }
  }
  echo "$echo";
}
</code></pre>

<p>I am trying to write code that accepts the message to send to another user if the recipient is in my database. The problem is that I think my condition <code>(if ($touser == $users)</code> is wrong. <code>$touser</code> refers to my <code>$_POST['recipient']</code> in my form and <code>$users</code> refer to the users in the database. </p>

<p>Could someone please review my code to ensure I'm on the right track?</p>
