title: Check if record exists: insert if no, display message if yes
body: <p>EDIT: Update! Got the first part working. However, I'm unsure how to also check for the other variables within the same IF() statement. Can anyone help me with that? The single if statement will refuse classes named exactly like the input. However, I need it to also refuse Days AND Times that are equal.</p>
  
  <pre><code>  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
      &lt;title&gt;Register Diver&lt;/title&gt;
      &lt;link rel="stylesheet" href="php_styles.css" type="text/css" /&gt;
      &lt;meta http-equiv="content-type"
      content="text/html; charset=iso-8859-1" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;h1&gt;Aqua Don's Scuba School&lt;/h1&gt;
      &lt;h2&gt;Registration Confirmation&lt;/h2&gt;
      &lt;?php
      $DiverID = $_GET['diverID'];
      if (empty($DiverID))
          exit("&lt;p&gt;You must enter a diver ID! Click your browser's Back button to return to the previous page.&lt;/p&gt;");
      $DBConnect = @mysqli_connect("localhost", "students", "password")
          Or die("&lt;p&gt;Unable to connect to the database server.&lt;/p&gt;"
          . "&lt;p&gt;Error code " . mysqli_connect_errno()
          . ": " . mysqli_connect_error()) . "&lt;/p&gt;";
      $DBName = "scuba_school";
      @mysqli_select_db($DBConnect, $DBName)
          Or die("&lt;p&gt;Unable to select the database.&lt;/p&gt;"
          . "&lt;p&gt;Error code " . mysqli_errno($DBConnect)
          . ": " . mysqli_error($DBConnect)) . "&lt;/p&gt;";
  
      $TableName = "registration";
      $SQLstring = "SELECT * FROM $TableName";
      $QueryResult = @mysqli_query($DBConnect, $SQLstring);
      if (!$QueryResult) {
          $SQLstring = "CREATE TABLE registration (diverID SMALLINT, class VARCHAR(40), days VARCHAR(40), time VARCHAR(40))";
          $QueryResult = @mysqli_query($DBConnect, $SQLstring)
              Or die("&lt;p&gt;Unable to create the registration table.&lt;/p&gt;"
              . "&lt;p&gt;Error code " . mysqli_errno($DBConnect)
              . ": " . mysqli_error($DBConnect)) . "&lt;/p&gt;";
          echo "&lt;p&gt;Successfully created the registration table.&lt;/p&gt;";
      }
      ?&gt;
  
      &lt;?php
      $Class = $_GET['class'];
      $Days = $_GET['days'];
      $Time = $_GET['time'];
      $DiverID = $_GET['diverID'];
  
      $DBConnect = mysqli_connect("localhost", "students", "password");
      $DBName = "scuba_school";
      @mysqli_select_db($DBConnect, $DBName)
          Or die("&lt;p&gt;Unable to select the database.&lt;/p&gt;"
          . "&lt;p&gt;Error code " . mysqli_errno($DBConnect)
          . ": " . mysqli_error($DBConnect)) . "&lt;/p&gt;";
  
  
      $sqlString= "SELECT * FROM `registration` WHERE `diverID` = $DiverID AND `class` = '$Class' AND `days` = '$Days' AND `time` = '$Time'";
      $QueryResult = mysqli_query($DBConnect, $sqlString) or die("MySQL error: " . mysqli_error($DBConnect) . "&lt;hr&gt;\nQuery: $QueryResult");  
      $row = mysqli_fetch_assoc($QueryResult);
  
      if ($row["class"] == $Class)
      {
  
      echo "&lt;p&gt;You are already registered for $Class&lt;/p&gt;";
          }
  
          elseif($row["days"] == $Days &amp;&amp; $row["time"] == $Time)
          {
              echo "&lt;p&gt;There is a conflict with $Days or $Time&lt;/p&gt;";
              }
      else
      {
       $SQLstring = "INSERT INTO $TableName VALUES('$DiverID', '$Class', '$Days', '$Time')";
          $QueryResult = @mysqli_query($DBConnect, $SQLstring);
          echo "&lt;p&gt;You are registered for $Class on $Days, $Time. Click your browser's Back button to register for another course or review your schedule.&lt;/p&gt;";
      }
  
  
      mysqli_close($DBConnect);
      ?&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>