当尝试使用PHP向MySQL数据库输入信息时出现不正确的错误


Incorrect error showing up when trying to use PHP to enter info into a MySQL database?

我试图创建一个PHP脚本连接HTML表单到MySQL数据库,一切都在工作,除了有一个输入不能为空,无论我做什么,系统似乎不认识当我输入文本到字段,我不知道我做错了什么。

下面是我的PHP代码:
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<br>'n";
    }
}
?>
下面是我的HTML代码:
<form action="register.php" method="post">
<p>Book name: <input type="text" name="book_name" size="20" maxlength="100" value="<?php if (isset($_POST['book_name'])) echo $_POST['book_name']; ?>" /></p>
<p>Author: <input type="text" name="author" size="20" maxlength="100" value="<?php if (isset($_POST['author'])) echo $_POST['author']; ?>" /></p>
<p>Publisher: <input type="text" name="publisher" size="20" maxlength="100" value="<?php if (isset($_POST['publisher'])) echo $_POST['publisher']; ?>" /></p>
<p>Language:</p>
<p>English <input type="radio" name="language_id" value="1" /></p>
<p>Spanish <input type="radio" name="language_id" value="2" /></p>
<p>French <input type="radio" name="language_id" value="3" /></p>
<p>Italian <input type="radio" name="language_id" value="4" /></p>
<p>Mandarin <input type="radio" name="language_id" value="5" /></p>
<p>Number of pages: <input type="text" name="length_pages" size="20" maxlength="100" value="<?php if (isset($_POST['length_pages'])) echo $_POST['length_pages']; ?>" /></p>
<p>Cover image file name: <input type="text" name="cover" size="20" maxlength="100" value="<?php if (isset($_POST['cover'])) echo $_POST['cover']; ?>" /></p>
<p>Is this book fiction?:</p>
<p>Yes <input type="radio" name="fiction" value="yes" /></p>
<p>No <input type="radio" name="fiction" value="no" /></p>
<p>Year Published: <input type="text" name="pub_year" size="20" maxlength="100" value="<?php if (isset($_POST['pub_year'])) echo $_POST['pub_year']; ?>" /></p>
<input type="submit" name="submit" value="submit" /></form>

不管什么原因,每次我试着测试它,我得到这个错误消息:

"系统错误。查询:INSERT INTO books(book_name, author, publisher, language_id, length_pages, cover, fiction, pub_year) VALUES (", 'Not Hayley Munguia', 'Random House', '2', '134', ' howtobenoral .jpg', 'no', '1938') -您忘记输入书名了。"

尽管我确实在书名字段中输入了一些东西

我真的不知道我做错了什么,感谢所有的帮助!谢谢你!

首先检查mysql中的句子并直接放入phpmyadmin中并查看错误。第二,我可以看到var book_name可能是空的