<分区>
我正在编写一段代码,允许用户相互发送消息。每当我尝试将消息插入数据库时,都会出现语法错误,但我终究无法弄清楚我的错误是什么。我知道问题不在 connect.php
中。此外,我正在为 $from
、$to
和 $message
获取适当的值,所以这不是问题所在。这是我的代码:
session_start();
require_once('../setup/connect.php');
$from = $_SESSION['id'];
$to = $_REQUEST['id'];
$message = trim($_POST['msg_body']);
$insert = "INSERT INTO messages(to, from, msg) VALUES('$to', '$from', '$message')";
mysql_query($insert) or die(mysql_error());
header("Location: view_profile.php?id=$to");
这是 mysql_error()
生成的报告:
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 'to, from, msg) VALUES('7', '6', 'Hey how are you?')' at line 1
这是我的数据库结构的图像:
感谢您的帮助!