title: MYSQL database not showing inserted data from HTML form
body: <p>I am fairly new to PHP and I was following a simple tutorial on youtube, I followed the youtube video, double and tripple checked to make sure everything I typed was correct and data was still not being inserted.</p>
  
  <p>I searched the internet for hours and I came up with a fix, sort of but I don't think it's the correct way to do it</p>
  
  <p>HTML </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;title&gt;Insert Form Data In MYSQL Database Using PHP&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form action="insert.php" method="post"&gt;
  
      Name : &lt;input type="text" name="username"&gt;
              &lt;br/&gt;
      Email : &lt;input type="text" name="email"&gt;
              &lt;br/&gt;
      &lt;input type="submit" value="Insert"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  
  $con = mysqli_connect('localhost','root','');
  
  if (!$con) {
      echo 'Not Connected To Server';
  }
  
  if (!mysqli_select_db($con,'tutorial')) {
      echo 'Database Not Selected';
  }
  
  if (isset($_POST['username'])){
      $Name = $_POST['username'];
  }
  
  if (isset($_POST['email'])){
      $Email = $_POST['email'];
  }
  
  $sql = "INSERT INTO person (Name, Email) VALUES ('John', 'john@gmail.com')";
  
  
  if (!mysqli_query($con,$sql)) {
      echo 'Not Inserted';
  } else {
      echo 'Inserted Successfully!';
  }
  header("refresh:10; url=index.html");
  ?&gt;
  </code></pre>
  
  <p>I replaced '$Name' and '$Email' with John and john@gmail.com, then I type it into the html form and the data goes into the database correctly.</p>
  
  <p>I then found another HTML form online with more PHP but it does the same thing(not inserting any data to the database)</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Add Record Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="insert1.php" method="post"&gt;
      &lt;p&gt;
          &lt;label for="firstName"&gt;First Name:&lt;/label&gt;
          &lt;input type="text" name="firstname" id="firstName"&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for="lastName"&gt;Last Name:&lt;/label&gt;
          &lt;input type="text" name="lastname" id="lastName"&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for="emailAddress"&gt;Email Address:&lt;/label&gt;
          &lt;input type="text" name="email" id="emailAddress"&gt;
      &lt;/p&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  /* Attempt MySQL server connection. Assuming you are running MySQL
  server with default setting (user 'root' with no password) */
  $link = mysqli_connect("localhost", "root", "", "demo");
  
  // Check connection
  if($link === false){
      die("ERROR: Could not connect. " . mysqli_connect_error());
  }
  
  // Escape user inputs for security
  $first_name = mysqli_real_escape_string($link, $_POST['firstname']);
  $last_name = mysqli_real_escape_string($link, $_POST['lastname']);
  $email_address = mysqli_real_escape_string($link, $_POST['email']);
  
  // attempt insert query execution
  $sql = "INSERT INTO persons (first_name, last_name, email_address) VALUES ('$first_name', '$last_name', '$email_address')";
  if(mysqli_query($link, $sql)){
      echo "Records added successfully.";
  } else{
      echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  }
  
  // close connection
  mysqli_close($link);
  ?&gt;
  </code></pre>
  
  <p>The fields are blank, any help will be greatly appreacited! </p>
  
  <p>Btw This is how the fields display I'm using xampp server. </p>
  
  <p><a href="https://i.stack.imgur.com/97tZt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/97tZt.jpg" alt="enter image description here"></a></p>