title: Returning True/False from PHP to Ajax
body: <p>The past day's I've been trying to return a true or false boolean to Ajax. </p>
  
  <p>The Process: Someone submit's a form > Send to a PHP file > From PHP, check everything is correct. If yes, return true and <code>echo 'correct'</code>. > Output the result. In this case, it'll have to echo correct. And check if it's true or false.</p>
  
  <p>The problem is, it will always return a false. Even when everything is correct. So when my login is correct, it will return a <code>correct</code>, as I expect. But it won't return a true.</p>
  
  <p>My form:</p>
  
  <pre><code>&lt;form id="loginform" class="col s12" name="loginform" method="post"&gt;
      &lt;div class="input-field col s12"&gt;
          &lt;i class="fas fa-user material-icons prefix"&gt;&lt;/i&gt;
          &lt;input id="hn" type="text" class="validate" name="hn"&gt;
          &lt;label for="hn"&gt;Gebruikersnaam&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input-field col s12"&gt;
          &lt;i class="fas fa-key material-icons prefix"&gt;&lt;/i&gt;
          &lt;input id="ww" type="password" class="validate" name="ww"&gt;
          &lt;label for="ww"&gt;Wachtwoord&lt;/label&gt;
      &lt;/div&gt;
      &lt;button class="mui-btn mui-btn--raised mui-btn--primary" id="forminlog"&gt;&lt;i class="fas fa-chevron-right"&gt;&lt;/i&gt; Inloggen&lt;/button&gt;
  </code></pre>
  
  <p>Ajax:</p>
  
  <pre><code>$("#forminlog").click(function(){
      $.ajax({
          type: 'POST',
          data: {hn: document.getElementById("hn").value, ww: document.getElementById("ww").value},
          url: 'login.php',
          success: function(output) {
              swal(output);
              if(output == true){
                  alert("true");
              } else {
                  alert("false");
              }
          }
      });
      event.preventDefault()
  });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  function login(){
      header('Content-Type', 'application/json');
      //VARIABLEN
      $pgebruiker = $_POST['hn'];
      $pww = $_POST['ww'];
      //LEGE VELDEN
      if(empty($pgebruiker) || empty($pww)){
          echo 'Vul alle velden in';
  
      }
      else {
          //DATA VANUIT DB
          include("connection.php");
          $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $sth = $dbh-&gt;prepare("SELECT * FROM gebruikers WHERE gebruikersnaam = :gebruiker");
          $pdoExec = $sth-&gt;execute(array(":gebruiker"=&gt;$pgebruiker));
          $sth-&gt;execute();
          $result = $sth-&gt;fetch(PDO::FETCH_OBJ);
          //GEBRUIKERSNAAM
          $gebruikersnaam = $result-&gt;gebruikersnaam;
          //WACHTWOORD
          $wachtwoord =  $result-&gt;wachtwoord;
          if(!strcasecmp($pgebruiker, $gebruikersnaam) == 0){
              echo 'Verkeerd gebruikersnaam.';
          }
          elseif(!password_verify($pww, $wachtwoord) /*strcasecmp($pww, $wachtwoord) == 0*/){
              echo 'Verkeerd wachtwoord';
          }
          else{
              echo 'Correcte gegevens.';
              return true;
              /*session_start();
              $_SESSION['gebruiker'] = $gebruikersnaam;
              header('Location: veilig.php');*/
              //exit;
          }
      }
  }
  login();
  ?&gt;
  </code></pre>