title: Cannot POST /register.php
body: <p>I'm new to PHP PDO and was trying to do a simple check. When a user signs up through the website, I want the code to check if the username or email has been used before and if it hasn't it will record the information to SQL. When I do a sign up, the page &quot;Cannot POST /register.php&quot; appears. This is my code:</p>
  <p><strong>HTML</strong> (signup.html)</p>
  <pre><code>&lt;body&gt;
       &lt;div class=&quot;square&quot;&gt;
          &lt;div class=&quot;form&quot;&gt;
      &lt;form name =&quot;myForm&quot; onsubmit=&quot;return letterCheck()&quot; form method=&quot;POST&quot; action=&quot;register.php&quot;&gt;
          &lt;h1&gt;Sign Up&lt;/h1&gt;
          &lt;label for=&quot;fname&quot;&gt; First Name: &lt;/label&gt;&lt;br&gt;
          &lt;input type=&quot;text&quot; id=&quot;fname&quot; name=&quot;fname&quot;&gt; &lt;br&gt;
          &lt;div class= &quot;error&quot; id=&quot;notification&quot;&gt;&lt;/div&gt;&lt;br&gt;
  
          &lt;label for=&quot;lname&quot;&gt; Last Name: &lt;/label&gt;&lt;br&gt;
          &lt;input type=&quot;text&quot; id=&quot;lname&quot; name=&quot;lname&quot;&gt; &lt;br&gt;
          &lt;div class= &quot;error&quot; id=&quot;notification2&quot;&gt;&lt;/div&gt;&lt;br&gt;
  
          &lt;label for=&quot;email&quot;&gt; E-mail: &lt;/label&gt;&lt;br&gt;
          &lt;input type=&quot;text&quot; id=&quot;email&quot; name=&quot;email&quot;&gt; &lt;br&gt;
          &lt;div class= &quot;error&quot; id=&quot;notification3&quot;&gt;&lt;/div&gt;&lt;br&gt;
  
          &lt;label for=&quot;uName&quot;&gt; Username: &lt;/label&gt;&lt;br&gt;
          &lt;input type=&quot;text&quot; id=&quot;uName&quot; name=&quot;uName&quot;&gt; &lt;br&gt;
          &lt;div class= &quot;error&quot; id=&quot;notification4&quot;&gt;&lt;/div&gt;&lt;br&gt;
  
          &lt;label for=&quot;pword&quot;&gt; Password: &lt;/label&gt;&lt;br&gt;
          &lt;input type=&quot;password&quot; id=&quot;pword&quot; name=&quot;pword&quot;&gt; &lt;br&gt;
          &lt;div class= &quot;error&quot; id=&quot;notification5&quot;&gt;&lt;/div&gt;&lt;br&gt;
  
  
              &lt;div class=&quot;buttons&quot;&gt;
                  &lt;a href=&quot;signin.html&quot;&gt;&lt;input class=&quot;button&quot; type=&quot;button&quot; value=&quot;Sign In&quot;&gt;&lt;/a&gt; 
                  
                  &lt;br&gt;
  
                  &lt;div class=&quot;right&quot;&gt;
                      &lt;input class =&quot;button&quot; id = &quot;submitButton&quot; type=&quot;submit&quot; value=&quot;Register&quot; style=&quot;float:right;&quot;&gt; &lt;br&gt; 
                  &lt;/div&gt;
              &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>PHP</strong> (register.php)</p>
  <pre><code>&lt;?php
  
  $host     = &quot;localhost&quot;;
  $user     = &quot;root&quot;;
  $password = &quot;&quot;;
  $db       = &quot;accountinfo&quot;;
  
  
  try {
      $conn = new PDO(&quot;mysql:host=$servername;dbname=$dbname&quot;, $username, $password);
      if( $conn != null ) {
          echo &quot;sucessfully connected&quot;;
      }
  } catch( PDOException $e ) {
      // echo &quot;Connection failed: &quot; . $e-&gt;getMessage();
      http_error(&quot;500 Internal Server Error\n\n&quot; . &quot;There was a SQL error:\n\n&quot; . $e-&gt;getMessage());
  }
  
  class runSql {
  
      function runQuery( $query, $conn ) {
          try {
              $q = $conn-&gt;prepare($query);
              $q-&gt;execute();
              $results = $q-&gt;fetchAll();
              $q-&gt;closeCursor();
  
              return $results;
          } catch( PDOException $e ) {
              http_error(&quot;500 Internal Server Error\n\n&quot; . &quot;There was a SQL error:\n\n&quot; . $e-&gt;getMessage());
          }
      }
  }
  
  function http_error( $message ) {
      header(&quot;Content-type: text/plain&quot;);
      die($message);
  }
  
  if( isset($_POST[&quot;submit&quot;]) ) {
      $firstname = $_POST['fname'];
      $lastname  = $_POST['lname'];
      $email     = $_POST['email'];
      $userName  = $_POST['uName'];
      $password  = $_POST['pword'];
  
      $sql_u = &quot;SELECT * FROM users WHERE username='$username'&quot;;
      $res_u = mysqli_query($db, $sql_u);
      if( mysqli_num_rows($res_u) &gt; 0 ) {
          $name_error = &quot;Sorry... username already taken&quot;;
      } else {
          $query = &quot;INSERT INTO signups (fname, lname, Email, password)
              VALUES ('$firstname', '$lastname', '$email', '$userName', '$password')&quot;;
      }
  }
  </code></pre>