title: Having problems comparing strings (PHP)
body: <p>My goal is to check if the value of the &quot;token&quot; stored in a cookie is the same as the value in the loginTable table in the db.
  I am able to save the value of the cookie in the variable $token. The problem I have is here --&gt; if ($row[&quot;token&quot;] == $token). For example the value of the $token is bm0h8sdigs and the value in the row is bm0h8sdigs, but it does not enter the if. I also tried strcmp function but it didn't work. if(strcmp($row[&quot;token&quot;], $token) == 0) I also tried $sqlToken = &quot;select * from loginTable where token='&quot; . $token . &quot;'&quot;; but it does not work.</p>
  <p>echo $token; prints what is in my cookie - bm0h8sdigs</p>
  <pre><code>&lt;!-- https://github.com/js-cookie/js-cookie This is a library to make handling cookies easier --&gt;
  &lt;script&gt;
     var token = Cookies.get('token');
  &lt;/script&gt;
  
  &lt;?php
     $token = &quot;&lt;script&gt;document.write(token)&lt;/script&gt;&quot;;
  
     $var = 0;
     include &quot;connectDB.php&quot;;
                                  
     $sqlToken = &quot;SELECT * FROM loginTable&quot;;
     $resultToken = $mysqli-&gt;query($sqlToken);
  
     while($row = $resultToken-&gt;fetch_assoc()){
          if ($row[&quot;token&quot;] == $token){
              $var = 1;
          }
     }
     $mysqli-&gt;close();
                                  
     if ($var == 1){
     //Token found in db
     }
     else{
     //Token not found in db
     }
  ?&gt;
  </code></pre>
  <p>connectDB.php</p>
  <pre><code>&lt;?php
      $host = &quot;localhost&quot;;
      $username = &quot;root&quot;;
      $password = &quot;usbw&quot;;
      $database = &quot;test&quot;;
  
      $mysqli = new mysqli($host, $username, $password, $database);
      $mysqli -&gt; set_charset(&quot;utf8&quot;);
  
      if ($mysqli-&gt;connect_errno) {
          echo &quot;Failed to connect to MySQL: (&quot; . $mysqli-&gt;connect_errno . &quot;) &quot; . $mysqli-&gt;connect_error; 
      }
  ?&gt;
  </code></pre>
  <p>loginTable - prnt.sc/u7nidn</p>
  <pre><code>Create table loginTable(
      loginID int AUTO_INCREMENT,
      userID int not null,
      token varchar(20) not null,
      Constraint PK_loginTable Primary Key(loginID),
      Constraint FK_loginTable_userID Foreign Key (userID) References usersTable (userID)
  )
  </code></pre>