title: When using a GET request to a PHP script the echoed result is not the right variable, its outputting the HTML of the page
body: <p>I am trying to check an email as a duplicate using a GET request to a PHP script. I have already gotten it to work for usernames on a different page. The sign-up page sends a request via the email type input box on blur.</p>
  <p>The HTML</p>
  <pre><code>&lt;div id=&quot;email-container&quot;&gt;
  
       &lt;label id=&quot;email-not-taken&quot; for=&quot;email&quot;&gt;Email&lt;/label&gt;
       &lt;img id=&quot;green-check&quot; src=&quot;../images/green-check.png&quot;&gt;
       &lt;label id=&quot;email-taken&quot;&gt;Email Taken&lt;/label&gt;
       &lt;input id=&quot;email-dc&quot; type=&quot;email&quot; name=&quot;email&quot; value=&quot; &quot;&gt;
  
  &lt;/div&gt;
  </code></pre>
  <p>So the result is a combination of that HTML showing if the email is already taken or not.</p>
  <p>At the bottom, it calls the signup.js script</p>
  <pre><code>&lt;script src=&quot;../js/signup.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>And here is signup.js</p>
  <pre><code>$('document').ready(function() {
  
      $('#email-dc').on('blur', function() {
  
          console.log(&quot;Inside blur&quot;); // I can get here
  
          var email = $('#email-dc').val();
          if (email == '') {
  
              email_state = false;
              console.log(&quot;Email Empty&quot;); // I can get here
              return;
  
          }
  
          var link = $('#email-dc').val();
  
          if (link == '') {
      
              // Do nothing
              
          } else {
      
              $.get(&quot;process.php?link=&quot;+link, function(data) {
  
                  console.log(data); // Right here it spits out the HTML of the page not $result
  
                  if (data == &quot;Taken&quot;) {
  
                      $(&quot;#email-dc&quot;).css(&quot;border&quot;,&quot;1px solid tomato&quot;);
                      $('#email-not-taken').css('display', 'none');
                      $('#email-taken').css('display', 'block');
                      $('#green-check').css('display', 'none');
  
                  } else if (data == &quot;Not Taken&quot;) {
  
                      $(&quot;#email-dc&quot;).css(&quot;border&quot;,&quot;1px solid #008000&quot;);
                      $('#email-not-taken').css('display', 'block');
                      $('#email-not-taken').css('color', '#008000');
                      $('#green-check').css('display', 'block');
                      $('#email-taken').css('display', 'none');
  
                  } else {
  
                      // Do Nothing
  
                  }
      
              });
      
          }
  
      });
  });
  </code></pre>
  <p>When it gets here</p>
  <pre><code>console.log(data);
  </code></pre>
  <p>It spits out the HTML of the page and not the fetched $result</p>
  <p>The link gets sent to process.php, which is this</p>
  <pre><code>&lt;?php
  
      SESSION_START();
  
      if (isset($_SESSION['email'])) {
  
          $email = $_SESSION['email'];
          $orig = $_SESSION['username'];
  
      } else {
  
          header(&quot;Location:login.php&quot;);
  
      }
  
      // Connect to the Database
  
      $dbc = mysqli_connect('localhost','root','','acoc_main_db') or die(&quot;Bad connection&quot;);
  
      $result = '';
  
      if (isset($_GET['link'])) {
  
          $link = $_GET['link'];
  
          if (filter_var($link, FILTER_VALIDATE_EMAIL)) {
  
              $sql = &quot;SELECT * FROM users WHERE email='$link'&quot;;
              $done = mysqli_query($dbc, $sql) or die(&quot;Bad sql: $sql&quot;);
              
              if (mysqli_num_rows($done) &gt; 0) {
      
                  $result = 'Taken';
      
              } else {
      
                  $result = 'Not Taken';
      
              }
  
          } else {
  
              $sql = &quot;SELECT * FROM users WHERE username='$link'&quot;;
              $done = mysqli_query($dbc, $sql) or die(&quot;Bad sql: $sql&quot;);
              
              if (mysqli_num_rows($done) &gt; 0 &amp;&amp; $link != $orig) {
      
                  $result = 'Taken';
      
              } else {
      
                  $result = 'Not Taken';
      
              }
  
          }
  
      }
  
      echo $result;
  
  ?&gt;
  </code></pre>
  <p>The if checks if it's an email and then runs the SQL commands to check for a duplicate and the else statement goes on if it's not an email, meaning it's a username and returns the $result (which the 'else check' on the username is working!).</p>
  <p>So I think it is broken somewhere here</p>
  <pre><code>        if (filter_var($link, FILTER_VALIDATE_EMAIL)) {
  
              $sql = &quot;SELECT * FROM users WHERE email='$link'&quot;;
              $done = mysqli_query($dbc, $sql) or die(&quot;Bad sql: $sql&quot;);
              
              if (mysqli_num_rows($done) &gt; 0) {
      
                  $result = 'Taken';
      
              } else {
      
                  $result = 'Not Taken';
      
              }
  
          } else {
  </code></pre>
  <p>The link in the email check is not assigning a 'Taken' or 'Not Taken' instead when I console log the resulting data it spits out the HTML of the page, not whether it found something in the SQL commands.</p>
  <p><a href="https://i.stack.imgur.com/nFnR1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nFnR1.jpg" alt="enter image description here" /></a></p>
  <p>Thanks for any input!</p>