【发布时间】:2020-03-16 21:35:15
【问题描述】:
请帮我解决这个错误。我厌倦了寻找解决方案... 错误:SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“WHERE name=NULL”附近使用正确的语法
我的数据库有 3 列=id(int),name(varchar),comment(varchar),我想在其中插入评论。
我的 php 代码:
<?php
include "./Config.php";
include './MyPDO.php';
$response = array() ;
$connect = MyPDO::getInstance();
$name = $_REQUEST['name'];
$comment=$_REQUEST['comment'];
$query = " INSERT INTO user "
. " (comment) "
. " VALUES "
. " (:comment) "
. " WHERE name=:name ";
$stmt = $connect->prepare($query);
$stmt->bindParam(":name",$name);
$stmt->bindParam(":comment",$comment);
try {
$stmt->execute();
$response['massage'] = "sucess";
echo json_encode($response);
exit;
} catch (PDOException $ex) {
$response['massage'] = "error";
$response['error']=$ex->getMessage();
echo json_encode($response);
}
【问题讨论】:
-
INSERT用于创建新行,UPDATE用于创建新行。在INSERT查询中使用WHERE是没有意义的。 -
谢谢,我刚学php一周..
标签: php mysql sql sql-update sql-insert