title: PHP - String comparison is not working
body: <p>I am setting up a login for a website (perhaps the way I am doing it is just wrong, but that's for another question).</p>
  
  <p>The way I am doing it is like this:</p>
  
  <ol>
  <li>Get username/password from user on login page.</li>
  <li>Pass these to my php using post.</li>
  <li>In the php, collect the values passed from post.</li>
  <li>Compare the password passed to PHP from post, with one taken from a MySQL database.</li>
  </ol>
  
  <p>I can get the database to connect.  I can extract the password from the database. I can collect the value from post.  But I CANNOT compare these two values - it always says they are not equal, even though echoing them says they are.</p>
  
  <p>To collect the posted values I use:</p>
  
  <pre><code>$posted_username = $_POST['uname'];
  $posted_password = $_POST['passwd'];
  </code></pre>
  
  <p>To query the DB I use:</p>
  
  <pre><code>$result = mysql_query("SELECT passwd FROM usrs where usrname = '".$posted_username."'");
  </code></pre>
  
  <p>Next, if I include this line:</p>
  
  <pre><code>echo "Posted Username: " . $posted_username . "&lt;br&gt;" . " Posted Password: " . $posted_password . "&lt;br&gt;";
  </code></pre>
  
  <p>I can see that my posted values have been assigned correctly.  I get this output when I run the PHP:</p>
  
  <blockquote>
    <p>Posted Username: admin
    Posted Password: admin2</p>
  </blockquote>
  
  <p>To step through my DB I use:</p>
  
  <pre><code>while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
  </code></pre>
  
  <p>And inside this while loop I go:</p>
  
  <pre><code>$password_fromdb = $row['passwd'];
  echo "Password from db is: " . $password_fromdb . "&lt;br&gt;";
  echo "Password from POST is: " . $posted_password . "&lt;br&gt;";
  $equal = strcmp($password_fromdb,$posted_password);
  </code></pre>
  
  <p>The output of the two echo lines gives me this:</p>
  
  <blockquote>
    <p>Password from db is: admin2
    Password from POST is: admin2</p>
  </blockquote>
  
  <p>So I can see that the two passwords DO match.</p>
  
  <p>However, whether I use strcmp, or whether I use =, == or ====, I ALWAYS get told that my two passwords do not match.  I get told they don't match even if they do!</p>
  
  <p>WHAT am I doing wrong? I would appreciate help as I know nothing about PHP, have to do this for a class, and our tutuor has decided he's not going to TEACH us PHP.</p>