简体   繁体   中英

PHP insert query gives syntax error but still writes into database

A query executes and writes into a database table and the field data is fetched and displayed in a WHILE loop so basically it works but I get a php error :

Error Inserting!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 \\'1\\' At Line 1

With line 1 being

<?php

I have tried playing around with commas and colons but I cannot get rid of the error. This is the query.

$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')";

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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