title: connecting and inserting data into database with mysqli
body: <p>I have been following some videos and other sources on how to connect to database. I am just new to programming and i can't  see where i have gone wrong with my connection. After heating the submit button on my form, the data seem to have been sent to database but after refreshing on my database, nothing is found. Your help is greatly appreciated. </p>
  
  <p>Here is my database connection code.</p>
  
  <pre><code> &lt;?php
  $db_host = 'localhost';
  $db_user = 'root';
  $db_pass = '';
  $db_name  = 'student_registration';
  $mysqli = new mysqli ($db_host, $db_user, $db_pass, $db_name);
  if ($mysqli -&gt; connect_errno){
      printf ("connect failed: %s/n", $mysqli -&gt; connect_error);
      }
      else printf ("connected to database");
  
  ?&gt;
  </code></pre>
  
  <p>Here is my insertion code.</p>
  
  <pre><code>&lt;?php
  require_once("opendb.php");
  
  if (isset($_POST['submit'])){   
  
  $department = $_POST['department'];
  $post = $_POST['post'];
  $description = $_POST['description'];
  $responsibility = $_POST['responsibility'];
  $requirement = $_POST['requirement'];
  $date=@"$_POST[year]"."-".@"$_POST[month]"."-".@"$_POST[day]";
  
  $query = "INSERT INTO posts VALUES('".$department."','".$post."','".$description."','".$responsibility."','".$requirement."','".$date."')";
  
  $inset = mysqli_query($mysqli, $query );
  if($inset){
  
            } 
  ?&gt;
  &lt;script language="javascript"&gt;
  alert("New Post Updated");
  window.location="addpost.php";
  &lt;/script&gt;
  
  &lt;?php
  } else{
   ?&gt;
  &lt;script language="javascript"&gt;
  alert("Post Updated did not update successfully Please try again");
  window.location="addpost.php";
  &lt;/script&gt; 
   &lt;?php 
   }
   ?&gt;  
  </code></pre>
  
  <p>The closing curly brace on if ($insert) is wrapping isset function. removing it renders the variables $department, $post etc as Unidentified variables.</p>