php - 插入语句不起作用

标签 php mysql sql syntax-error

我一直使用普通查询将数据插入数据库,但现在我想用准备好的语句来实现。我已经在使用语句来选择我所有文件中的数据,但插入从来没有用过……现在我又没主意了。也许有人可以看出我做错了什么。

$animeId        =   $_POST['animeId'];
$username   =   $_POST['username'];
$rating         =   $_POST['rating'];
$story          =   $_POST['story'];
$genre          =   $_POST['genre'];
$animation  =   $_POST['animation'];
$characters =   $_POST['characters'];
$music          =   $_POST['music'];

//Datum auslesen
$date =  date("Y-m-d H:i:s");


if($insertRating = $con->prepare("INSERT INTO anime_rating (animeId, rating, story, genre, animation, characters, music, user, date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?"))
{
    $insertRating->bind_param("iiiiiiiss", $animeId, $rating, $story, $genre, $animation, $characters, $music, $username, $date);
    $insertRating->execute();
    $insertRating->close();
}

最佳答案

您的查询中有一个错误的逗号:

music, user,) VALUES (?, ?, ?, ?, ?, ?, ?                               
          ^^^
          HERE

应该是

music, user) VALUES (?, ?, ?, ?, ?, ?, ?     

关于php - 插入语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22212992/

相关文章:

php - 如何删除数组中小于 X 的整数?

php - 准备好的语句不获取数据

javascript - 如何在 MVC(AngularJS、HTML、PHP)中显示来自 SQL 数据库的特定数据

mysql - 在 MySQL 查询的 WHERE 子句中使用列别名会产生错误

php - 保持用户特定 session 信息安全的最佳方式

php - 将Mysql数据添加到外部javascript文件中的js var中

php 使用上一页中的参数选择查询

具有排名行的 MySql View

php - 使用 Drupal 内容类型中的数据库自动完成字段

SQL 将现有/重复的行插入表中但只更改一列值?