undefined index - register form : <pre><code>    &lt;?php

$mysqli = mysqli_connect('localhost', 'test', 'test123', 'test'); 

if ($mysqli-&gt;connect_errno) {
    echo "&lt;p&gt;MySQL error no {$mysqli-&gt;connect_errno} : {$mysqli-&gt;connect_error}&lt;/p&gt;"; 
    exit();
}

global $mysqli;
$username   = $_POST['username']; 
$password   = $_POST['password'];
$firstname  = $_POST['firstname'];
$lastname   = $_POST['lastname'];
$email      = $_POST['email'];

$exists = 0;
$result = $mysqli-&gt;query("SELECT username from users WHERE username = '{$username}' LIMIT 1"); 
if ($result-&gt;num_rows == 1) { 
    $exists = 1; 
    $result = $mysqli-&gt;query("SELECT password from users WHERE password = '{$password}' LIMIT 1"); 
    if ($result-&gt;num_rows == 1) $exists = 2; 
} else {
    $result = $mysqli-&gt;query("SELECT email from users WHERE email = '{$email}' LIMIT 1"); 
    if ($result-&gt;num_rows == 1) $exists = 3; 
}

if ($exists == 1) echo "&lt;p&gt;Username already exists!&lt;/p&gt;"; 
else if ($exists == 2) echo "&lt;p&gt;Username and Email already exists!&lt;/p&gt;"; 
else if ($exists == 3) echo "&lt;p&gt;Email already exists!&lt;/p&gt;"; 
else {
    # insert data into mysql database
    $sql = "INSERT  INTO `users` (`id`, `username`, `password`, `firstname`, `lastname`, `email`) 
            VALUES (NULL, '{$username}', '{$password}', '{$firstname}', '{$lastname}', '{$email}')";

    if ($mysqli-&gt;query($sql)) {
        //echo "New Record has id ".$mysqli-&gt;insert_id; 
        echo '&lt;meta http-equiv="refresh" content="0; url=test.html"&gt;'; 
    } else {
        echo "&lt;p&gt;MySQL error no {$mysqli-&gt;errno} : {$mysqli-&gt;error}&lt;/p&gt;"; 
        exit();
    }
}
?&gt;      
</code></pre>

<p>I am trying to create a register page, so when the user fills in the relevant details it register them to the database in MYSQL and stores details.</p>

<p>Therfore they can then go ahead to login, the error I am having is 'Undefined index' showing on all variables - username, password, firstname, lastname and email.</p>

<p>I have added all these variables to my backend db but still nothing..</p>

<p>HTML code:</p>

<pre><code>&lt;body&gt;
    &lt;div class="container"&gt;
      &lt;h1 class="text-center"&gt;Booking&lt;/h1&gt;
      &lt;form class="form-signin" method="POST" action="register.php"&gt;
        &lt;h2 class="form-signin-heading"&gt;Register&lt;/h2&gt;
        &lt;div id="all-form"&gt;
        &lt;h3&gt;User Details&lt;/h3&gt;
        &lt;input required type="text" class="form-control" placeholder="Name"&gt;
        &lt;input required type="text" class="form-control" placeholder="Email Address"&gt;
        &lt;h4&gt;Login Details&lt;/h4&gt;
        &lt;input required type="text" class="form-control" placeholder="Username"&gt;
        &lt;input required type="password" class="form-control" placeholder="Password"&gt;
        &lt;input required type="password" class="form-control" placeholder="Confirm Password"&gt;
        &lt;button class="btn btn-primary btn-sm" type="register"&gt;Register&lt;/button&gt;
        &lt;p&gt;&lt;a href="signup2.html"&gt;Already registered? Sign in here &lt;/a&gt;&lt;/p&gt;
      &lt;/form&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;!-- /container --&gt;
  &lt;/body&gt; 
</code></pre>
