title: Cannot insert data into MySQL Database
body: <p>So I'm having kind of a problem here. I'm trying to do something very basic, which is store data via Apache localhost website into a MySQL Database. After I send the data on my website, it's not stored into the database. I will post my code first and then give you some more info:</p>
  
  <p>Code in header:</p>
  
  <pre><code>&lt;?php
  $link=mysqli_connect("localhost","root","mypassword","database") or die("Couldn't connect to DB");
  ?&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php include ( "./inc/header.inc.php" ); ?&gt;
  &lt;?php
  $reg = @$_POST['reg'];
  // declaring variables to prevent errors
  $fn = ""; // First Name
  $ln = ""; // Last Name
  $un = ""; // Username
  $em = ""; // Email
  $emc = ""; // Emailcheck
  $pswd = ""; // Password
  $pswdc = ""; // Passwordcheck
  $d = ""; // Signup Date
  $u_check = ""; // Check if username exists
  // registration form
  $fn = strip_tags(@$_POST['fname']);
  $ln = strip_tags(@$_POST['lname']);
  $un = strip_tags(@$_POST['username']);
  $em = strip_tags(@$_POST['email']);
  $emc = strip_tags(@$_POST['emailcheck']);
  $pswd = strip_tags(@$_POST['password']);
  $pswdc = strip_tags(@$_POST['passwordcheck']);
  date_default_timezone_set('Europe/Berlin');
  $d = date("Y-M-D"); // Year - Month - Day
  
  if ($reg) {
      // Check if emails are equal
      if ($em==$emc) {
          // Check if user already exists
          $u_check = mysqli_query($link, "SELECT username FROM users WHERE username= '$un'");
          // Count the amount of rows where username = $un
          $check = mysqli_num_rows($u_check);
          if ($check == 0) {
              // Check all of the fields have been filled in
              if ($fn&amp;&amp;$ln&amp;&amp;$un&amp;&amp;$em&amp;&amp;$emc&amp;&amp;$pswd&amp;&amp;$pswdc) {
                  // Check that passwords match
                  if ($pswd==$pswdc) {
                      // Check the max length of username/first name/last name does not exeed 25 characters
                      if (strlen($un)&gt;25||strlen($fn)&gt;25||strlen($ln)&gt;25) {
                          echo "The maximum limit for username/first name/last name is 25 characters!";
                      } else {
                          // Check the max length of password does not exeed 25 characters and is not less than 5 characters
                          if (strlen($pswd)&gt;30||strlen($pswd)&lt;5) {
                              echo "Your password must be between 5 and 30 characters long. So should your ######!";
                          } else {
                              // encrypt password and passwordcheck using md5 before sending to database
                              $pswd = md5($pswd);
                              $pswdc = md5($pswdc);
                              $query = mysqli_query($link, "INSERT INTO users (id, username, first_name, last_name, email, password, sign_up_date, activated) VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
                              die("&lt;h2&gt;Welcome to #######&lt;/h2&gt;Login to your account to get ######!");
                          }
                      }
                  } else {
                      echo "Your passwords don't match.";
                  }
              } else {
                  echo "Please fill in all of the fields.";
              }
          } else {
              echo "This Username already exists.";
          }
      } else {
          echo "Your Emails don't match.";
      }
  }
  ?&gt;
          &lt;div id="wrapper2"&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td width="60%" valign="top"&gt;
                          &lt;h2&gt;Join ####### today!&lt;/h2&gt;
                      &lt;/td&gt;
                      &lt;td width="40%" valign="top"&gt;
                          &lt;h2&gt;Sign up below.&lt;/h2&gt;
                          &lt;form action="#" method="POST"&gt;
                              &lt;input type="text" name="fname" size="25" placeholder="First Name" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="lname" size="25" placeholder="Last Name" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="username" size="25" placeholder="User Name" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="email" size="25" placeholder="E-Mail" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="emailcheck" size="25" placeholder="E-Mail Check" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="password" size="25" placeholder="Password" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="passwordcheck" size="25" placeholder="Password Check" /&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="submit" name="reg" value="Sign Up!"&gt;
                          &lt;/form&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  &lt;?php include ( "./inc/footer.inc.php" ); ?&gt;
  </code></pre>
  
  <p>So the connection to the database is working. I already checked that. The data is correctly stored in the variables. I manually inserted a 'Test' username via phpMyAdmin in the database and if I put the same username in my website, the code correctly fetches the username from the database and compares it with the input (ergo the result is "Username already exists"). Like I already said, when I fill the form correctly with data, the code terminates but the data is not stored into the database.</p>
  
  <p>Here some version info:
  Apache/2.4.16 (Unix) PHP/5.5.29</p>
  
  <p>Basically used this guide to set up Apache, PHP, MySQL, phpMyAdmin:
  <a href="http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/" rel="nofollow noreferrer">Guide for Mac OSX</a></p>
  
  <p>I checked for errors via <code>die(mysqli_error($link));</code>, and got this response:</p>
  
  <blockquote>
    <p>Incorrect integer value: '' for column 'id' at row 1 ->Changed argument '' to NULL.</p>
  </blockquote>
  
  <p>Second error check gave me this:</p>
  
  <blockquote>
    <p>Incorrect date value: '2015-Nov-Wed' for column 'sign_up_date' at row 1</p>
  </blockquote>
  
  <p>The <code>NOW()</code> method did the trick. And thanks for pointing out the date mistake: should be $d = date("Y-m-d"); </p>