gpt4 book ai didi

mysql - 将日期插入 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-30 00:09:00 25 4
gpt4 key购买 nike

我正在编写一个脚本来将书籍数据插入数据库。

这是插入数据的代码

$errors=array();

foreach(array('title','author','publisher','pub_date','isbn','Format','genre','category','bookcase','shelf','user_id') as $key=>$val){

$_REQUEST[$key] = mysqli_real_escape_string($ptah,trim($_REQUEST[$val])) ;

};
$title = $_REQUEST['title'] ; $title = strip_tags($title);

$author = $_REQUEST['author'] ; $author = strip_tags($author);

$publisher = $_REQUEST['publisher'] ; $publisher = strip_tags($publisher);

$pub_date = $_REQUEST['pub_date'] ; $pub_date = strip_tags($pub_date);

$isbn = $_REQUEST['isbn'] ; $isbn = strip_tags($isbn);

$format = $_REQUEST['Format'] ; $format = strip_tags($format);

$genre = $_REQUEST['genre'] ; $genre = strip_tags($genre);

$category = $_REQUEST['category'] ; $category = strip_tags($category);

$bookcase = $_REQUEST['bookcase'] ; $bookcase = strip_tags($bookcase);

$shelf = $_REQUEST['shelf'] ; $shelf = strip_tags($shelf);

$username = $_REQUEST['user_id'] ; $username = strip_tags($username);

# On success, register user
if (empty($errors))

# Insert the user into the database
{
$insert_sql = "INSERT INTO library (title, author, publisher, pub_date, isbn, format, genre, category, bookcase, shelf, time_entered, by) VALUES ( '$title', '$author', '$publisher', '$pub_date', '$isbn', '$format', '$genre', '$category', '$bookcase', '$shelf', NOW(), '$username' )";
mysqli_query($ptah,$insert_sql) or die(mysqli_error($ptah));

mysqli_close($ptah);
exit();
};
?>

提交后,我收到以下错误。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ( 'Gently Does It', 'Hunter Alan', 'Robinson', '2010', '1234567890', ' at line 1

这完全遗漏了格式、流派、类别、书柜、书架、输入日期以及由谁输入。

有趣的是,要提交的数据量会根据各个片段的长度而变化,

例如

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ( 'The Hundred Year Old Man Who Climbed Out of a Window And Disappear' at line 1 doesn't even finish the title whereas

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ( 'a', 'b', 'c', '1234', '1', 'Paperback', 'Fiction', 'Fantasy', 'a1'' at line 1 makes it as far as bookcase.

我被难住了。有人可以帮忙吗?

最佳答案

BY 是 MySQL 中的保留字,因此您应该使用反引号 ` 对其进行转义,以防您需要将其用作字段名称。

<...> , time_entered, `by`) <...>

关于mysql - 将日期插入 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24243284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com