title: Notice: Undefined variable: on insert
body: <p>I am pretty new to PHP and ran into a problem. I am trying to check if an id exists in the table and if not then insert the records but running into trouble. I currently have:</p>
  
  <pre><code>            &lt;?php
  
              if(isset($_POST['add'])){
              $id              = $_POST['id'];
              $first_name      = $_POST['first_name'];
              $last_name       = $_POST['last_name'];
              $dob             = $_POST['dob'];
              $telephone       = $_POST['telephone'];
              $job_title       = $_POST['job_title'];
              $site            = $_POST['site'];
              $department      = $_POST['department'];
              $email           = $_POST['email'];
              $pass1           = $_POST['pass1'];
              $pass2           = $_POST['pass2'];
  
  
              $cek = mysqli_query($db, "SELECT * FROM employees WHERE id='$id'");
              if(mysqli_num_rows($cek) == 0){
  
                  if($pass1 == $pass2){
                      $pass = md5($pass1);
                      $insert = mysqli_query($db, "INSERT INTO employees (id, first_name, last_name, dob, telephone, job_title, site, department, email, password)
                                                          VALUES('$id','$first_name', '$last_name', '$dob', '$telephone', '$job_title', '$site', '$department', '$email', '$pass')") or die('Error: ' . mysqli_error($db));
                      if($insert){
                          echo '&lt;div class="alert alert-success alert-dismissable"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;Employee added&lt;/div&gt;';
                      }else{
                          echo '&lt;div class="alert alert-danger alert-dismissable"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;Ups, Error, user not added&lt;/div&gt;';
                      }
                  } else{
                      echo '&lt;div class="alert alert-danger alert-dismissable"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;Passwords do not match&lt;/div&gt;';
                  }
              }else{
                  echo '&lt;div class="alert alert-danger alert-dismissable"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;Employee Id Exists&lt;/div&gt;';
              }
          }
          ?&gt;
  </code></pre>
  
  <p>I am encountering a error: Notice: Undefined variable: db </p>
  
  <p>I have tried to google but no avail so far. Anyone have any ideas?</p>
  
  <p>The error points to line 76 which is </p>
  
  <pre><code>        $cek = mysqli_query($db, "SELECT * FROM employees WHERE id='$id'");
  </code></pre>