title: check if username and email already exists in database
body: <p>I just started with php and i tried to create system to reject "create account" if you type already existing username or password.Thank you,and sorry for my bad english.
  <strong>I already tried this.Not working: <a href="https://stackoverflow.com/questions/42460896/check-username-and-email-already-exists-in-php-mysql">link</a></strong></p>
  
  <h2>This is my php:</h2>
  
  <pre><code>&lt;?php
  session_start();
  
  $db = mysqli_connect("localhost", "root", "", "itsnikola");
  
  if (isset($_POST['register_btn'])) {
      $name = mysqli_real_escape_string($db, $_POST['name']);
      $lastname = mysqli_real_escape_string($db, $_POST['lastname']);
      $username = mysqli_real_escape_string($db, $_POST['username']);
      $email=mysqli_real_escape_string($db, $_POST['email']);
      $password=mysqli_real_escape_string($db, $_POST['password']);
      $password2=mysqli_real_escape_string($db, $_POST['password2']);
  
      if ($password == $password2) {
          session_start();
          $password = ($password);
          $sql="select * from account_info where (username='$username' or email='$email')";
  
          if (mysqli_num_rows($res) &gt; 0) {
            $row = mysqli_fetch_assoc($res);
            if ($username==$row['username'])
            {
                $_SESSION['message'] = "Username je vec registrovan";
            }
            else($email==$row['email']){
                $_SESSION['message'] = "Email je vec registrovan"
            }
         else
          {
          $sql = "INSERT INTO users(name, lastname, username, email, password) VALUES('$name' , '$lastname' , '$username' , '$email' , '$password')";
          mysqli_query($db, $sql);
          $_SESSION['message'] = "Sada si ulogovan";
          $_SESSION['message'] = $username;
          header("location:login.php");
      }else {
          $_SESSION['message'] = "Ne podudaraju se lozinke!";
      }
  }
  ?&gt;
  </code></pre>