我确信这是我所缺少的愚蠢的东西,但有谁能确定为什么下面的方法行不通:
#sanitise variables
$player1 = GetSQLValueString($_POST['player1'], "text");
$battle = GetSQLValueString($_POST['battle'], "text");
$subject = "You Have Registered For ".$battle."";
$subject = GetSQLValueString($subject, "text");
$message = "You Have Registered For ".$battle."<br /><br />
Keep an eye on your PM's, it won't take long before your challenger appears!";
$message = GetSQLValueString($message, "text");
echo $player1;
echo "<br />";
echo $subject;
echo "<br />";
echo $message;
echo "<br />";
echo $time;
echo "<br />";
#insert alerts into private message databases
mysql_select_db($database_conn, $conn);
$query_rsSendAlert = "INSERT INTO site_private_messages
(sender, recipient, read_status, subject, message, `timestamp`)
VALUES ('Admin', $player1, 'n', $subject, $message, `$time`)";
mysql_query($query_rsSendAlert, $conn) or die(mysql_error());
回声只是为了在插入之前我能看到变量(换言之,有助于发现问题)。下面是一个例子:
'ferdia'
'You Have Registered For \'Fifa 11 Fracus!\''
'You Have Registered For \'Fifa 11 Fracus!\'
Keep an eye on your PMs, it won\'t take long before your challenger appears!'
1304866340
表格格式如下:
CREATE TABLE `site_private_messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sender` varchar(30) DEFAULT NULL,
`recipient` varchar(30) DEFAULT NULL,
`read_status` varchar(1) DEFAULT NULL,
`subject` varchar(200) DEFAULT NULL,
`message` text,
`timestamp` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=39 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
有什么建议吗?
最佳答案
很可能,您会发现列名时间戳是一个保留字。
如果要将保留字用作列名或表名,则必须将它们括在backticks
但是,回显实际的SQL语句,并进行错误处理,以确定您得到的确切错误消息。养成在使用SQL时使用错误处理的习惯,如果让PHP在出现MySQL错误时实际显示任何错误,这将为您节省很多麻烦。
关于php - INSERT由于某种原因无法运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5928143/