title: How to check if a row exists in MySQL? (i.e. check if username or email exists in MySQL)
body: <p>I need help checking if a row exists in the database. In my case, that row contains an email address. I am getting the result:</p>
  <pre class="lang-none prettyprint-override"><code>email no longer exists publisher@example.com
  </code></pre>
  <p>This is the code I'm currently using:</p>
  <pre><code>if (count($_POST)) {
      $email = $dbl-&gt;real_escape_string(trim(strip_tags($_POST['email'])));
  
      $query = &quot;SELECT `email` FROM `tblUser` WHERE `email` = '$email'&quot;;
      $result = mysqli_query($dbl, $query);
      if (is_resource($result) &amp;&amp; mysqli_num_rows($result) == 1) {
          $row = mysqli_fetch_assoc($result);
          echo $email . &quot; email exists &quot; .  $row[&quot;email&quot;] . &quot;\n&quot;;
      } else {
          echo &quot;email no longer exists&quot; . $email . &quot;\n&quot;;
      }
  }
  </code></pre>
  <p>Is there a better way to check if a row exists in MySQL database (in my case, check if an email exists in MySQL)?</p>