繁体   English   中英

PHP插入查询给出语法错误,但仍写入数据库

[英]PHP insert query gives syntax error but still writes into database

查询执行并写入数据库表,并且字段数据被提取并显示在WHILE循环中,因此基本上可以正常工作,但我收到了php错误:

错误插入!您的Sql语法有错误; 检查与您的Mysql Server版本相对应的手册,以在第1行上在\\'1 \\'附近使用正确的语法

随着第1行

<?php

我曾尝试使用逗号和冒号,但我无法摆脱错误。 这是查询。

$Link = mysql_connect($Host, $User, $Password);
$user = $_SESSION['UserName'];

$query = mysql_query("INSERT INTO films VALUES ('0', '".($user)."','".($formValue["subject"])."',NOW(),'".($usercomments)."','".($formValue["rating"])."','action')");

if(mysql_query ($query, $Link)){
$message = "Thank you for your comments";
header("Location: films.php?message=$message");
}else{
$message = "Error Inserting!" . mysql_error();
header("Location: films.php?message=$message");
$query = "INSERT INTO films VALUES ('0', '$user','$formValue[subject]',NOW(),'$usercomments','$formValue[rating]','action')";

这可以简化代码并解决您的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM