不确定为什么它会返回此错误,我找不到错误!
有人可以帮帮我吗?
代码:
$user = user($_SESSION["uid"],"*");
ini_set('display_errors',1);
error_reporting(E_ALL);
if(isset($_POST["submit"])){
if(!empty($_POST["message"])){
if(!empty($_POST["title"])){
$title = $_POST['title'];
$message = $_POST['message'];
$result = mysql_query("INSERT INTO `tickets` (`id`, `username`, `title`, `message`, `date`) VALUES (NULL, '$user', '$title', '$message', NOW()");
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
echo "<p class='box green'>Successfully created ticket.</p>";
}
} else {
echo "<p class='box red'>You left the title field blank!</p>";
}
} else {
echo "<p class='box red'>You left the message field blank!</p>";
}
错误:
Invalid query: 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 '' at line 1
答案 0 :(得分:1)
您在查询结束时忘记关闭括号。
这一行:
$result = mysql_query("INSERT INTO `tickets` (`id`, `username`, `title`, `message`, `date`) VALUES (NULL, '$user', '$title', '$message', NOW()");
应该是:
$result = mysql_query("INSERT INTO `tickets` (`id`, `username`, `title`, `message`, `date`) VALUES (NULL, '$user', '$title', '$message', NOW())");