title: Incorrect error showing up when trying to use PHP to enter info into a MySQL database?
body: <p>I'm trying to create a PHP script to connect an HTML form to a MySQL database, and everything is working except there is one input that cannot be null, and no matter what I do, the system doesn't seem to recognize when I enter text into the field, and I have no idea what I'm doing wrong.</p>
  
  <p>Here's my PHP code:
       
  
  <pre><code>if (empty($_POST['book_name']))
  {$errors[ ] = 'You forgot to enter the book name.';
  }
  else    {
      $booktitle = trim($_POST['book_name']);
  }
  
  if (empty($_POST['author']))
  {$errors[ ] = 'You forgot to enter the author.';
  }
  else    {
      $author = trim($_POST['author']);
  }
  
  if (empty($_POST['cover']))
  {$errors[ ] = 'You forgot to enter the book cover image.';
   }
  else    {
      $cover = trim($_POST['cover']);
  }
  
  if (empty($_POST['publisher']))
  {$errors[ ] = 'You forgot to enter the publisher.';
   }
  else    {
      $publisher = trim($_POST['publisher']);
  }
  
  if (empty($_POST['language_id']))
  {$errors[ ] = 'You forgot to enter the book language.';
  }
  else    {
      $languageid = trim($_POST['language_id']);
  }
  
  if (empty($_POST['length_pages']))
  {$errors[ ] = 'You forgot to enter the book length in pages.';
  }
  else    {
      $lengthpages = trim($_POST['length_pages']);
  }
  
  if (empty($_POST['fiction']))
  
  {$errors[ ] = 'You forgot to enter if the book is fiction or not.';
  }
  else    {
      $fiction = trim($_POST['fiction']);
  }
  
  if (empty($_POST['pub_year']))
  {$errors[ ] = 'You forgot to enter the year the book was published.';}
  
  else    {
      $pubyear = trim($_POST['pub_year']);
  
  }
  
      if (empty($errors)) {
  require ('mysqli_connect.php');
  
  
  }
  
  $q = "INSERT INTO books(book_name, author, publisher, language_id, length_pages, cover, fiction, pub_year) VALUES
  ('$booktitle', '$author', '$publisher', '$languageid', '$lengthpages', '$cover', '$fiction', '$pubyear')";
  $r = @mysqli_query($dbc, $q);
  
  
  
   if ($r) {
      echo 'Thank you! This book information has been entered into the database.';
  }
  
   else {
      echo 'System error.';
      echo mysqli_error($dbc) . ' Query: ' . $q;
      foreach ($errors as $msg) {
          echo " - $msg&lt;br&gt;\n";
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>and here's my HTML code:</p>
  
  <pre><code>&lt;form action="register.php" method="post"&gt;
  &lt;p&gt;Book name: &lt;input type="text" name="book_name" size="20" maxlength="100" value="&lt;?php if (isset($_POST['book_name'])) echo $_POST['book_name']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;p&gt;Author: &lt;input type="text" name="author" size="20" maxlength="100" value="&lt;?php if (isset($_POST['author'])) echo $_POST['author']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;p&gt;Publisher: &lt;input type="text" name="publisher" size="20" maxlength="100" value="&lt;?php if (isset($_POST['publisher'])) echo $_POST['publisher']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;p&gt;Language:&lt;/p&gt;
  &lt;p&gt;English &lt;input type="radio" name="language_id" value="1" /&gt;&lt;/p&gt;
  &lt;p&gt;Spanish &lt;input type="radio" name="language_id" value="2" /&gt;&lt;/p&gt;
  &lt;p&gt;French &lt;input type="radio" name="language_id" value="3" /&gt;&lt;/p&gt;
  &lt;p&gt;Italian &lt;input type="radio" name="language_id" value="4" /&gt;&lt;/p&gt;
  &lt;p&gt;Mandarin &lt;input type="radio" name="language_id" value="5" /&gt;&lt;/p&gt;
  &lt;p&gt;Number of pages: &lt;input type="text" name="length_pages" size="20" maxlength="100" value="&lt;?php if (isset($_POST['length_pages'])) echo $_POST['length_pages']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;p&gt;Cover image file name: &lt;input type="text" name="cover" size="20" maxlength="100" value="&lt;?php if (isset($_POST['cover'])) echo $_POST['cover']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;p&gt;Is this book fiction?:&lt;/p&gt;
  &lt;p&gt;Yes &lt;input type="radio" name="fiction" value="yes" /&gt;&lt;/p&gt;
  &lt;p&gt;No &lt;input type="radio" name="fiction" value="no" /&gt;&lt;/p&gt;
  &lt;p&gt;Year Published: &lt;input type="text" name="pub_year" size="20" maxlength="100" value="&lt;?php if (isset($_POST['pub_year'])) echo $_POST['pub_year']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;input type="submit" name="submit" value="submit" /&gt;&lt;/form&gt;
  </code></pre>
  
  <p>And for whatever reason, every time I try to test it out, I get this error message: </p>
  
  <blockquote>
    <p>"System error. Query: INSERT INTO books(book_name, author, publisher, language_id, length_pages, cover, fiction, pub_year) VALUES ('', 'Not Hayley Munguia', 'Random House', '2', '134', 'howtobenormal.jpg', 'no', '1938') - You forgot to enter the book name."</p>
  </blockquote>
  
  <p>even though I'm definitely inputting something into the book name field.</p>
  
  <p>I really have no idea what I'm doing wrong, all help is appreciated! Thank you!</p>