我收到此错误错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行的“to, from, message, read) VALUES ('3','2','testmessage','0')' 附近使用的正确语法。
我已经在这里工作了几个小时,但在 SO 或任何其他网站上什么也没找到。在此先感谢您的帮助。下面是一个简单的消息系统文件。
<?php
session_start();
$id = $_SESSION['id'];
$msg = $_POST['message'];
$theirs = $_POST['value'];
$read = 0;
$con = mysql_connect("127.0.0.1","root","");
mysql_select_db("test", $con);
if (!$con)
die('Could not connect: ' . mysql_error());
$sql = "INSERT INTO messages (to, from, message, read) VALUES ('$theirs','$id','$msg','$read')";
if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());
mysql_close($con);
最佳答案
to
、from
和read
是reserved words在 MySQL 中。用反引号引用它们
INSERT INTO messages (`to`, `from`, `message`, `read`) VALUES ('$theirs','$id','$msg','$read')
关于php - MySql语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14086843/