title: PHP and MySQL string comparison failing
body: <p>Okay, so I'm having a pretty annoying little problem with my php code. Basically I pull two variables from two seperate sources. One's a cookie and the other is from a MySQL database.</p>
  
  <pre><code>$data = explode("|", $_COOKIE['login']);
  $sql = "SELECT session_id FROM users WHERE username='user1'";
  $result = $data-&gt;query($sql);
  $row = $result-&gt;fetch_assoc();
  
  $test1 = $data[0];
  $test2 = $row['session_id'];
  
  If($test1 == $test2) {
    // Do some stuff
  }
  else {
    // Don't do some stuff
  }
  </code></pre>
  
  <p>The actual string is:</p>
  
  <p>x6vkYu6Ep^lm(1Rdm)5Gj5Hj7ilL6FsDL88JC#n@iTyBUqYgJ48#9Ow%*2ZdGs1rA8bc)JoCD7dywcZgg7soV0D#!DpR^pjQwF#QpBt#HRKe$JEtQ*3LhFXsjmkzWNpt</p>
  
  <p>The string is randomly generated before being stored from the following character set:
  1234567890!@#$%^&amp;*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
  
  <pre><code>for($i = 0; $i &lt; 128; $i++) {
    $string .= $char_set[rand(0, strlen($char_set)-1)];
  }
  $sql = "UPDATE users SET session_id='$string' WHERE user='user1'";
  $data-&gt;query($sql);
  setcookie('login', $string . "|" . $username);
  </code></pre>
  
  <p>If I just set the two variables equal to the above string and evaluate, it works out just fine. Also, if I echo both $data[0] and $row['session_id'] the entire string will display, and they look indentical.</p>
  
  <p>The if() statement will work if I use basic strings, like a number, or basic word, so I'm guessing it's due to special characters, but I don't know where in the proccess it goes wrong. As I said, if I set two variables to that string value, it evaluates, but when I pull from MySQL and the cookie, despite that both strings look the same, it won't evaluate.</p>
  
  <p>Any thoughts?</p>