我正在尝试使用 PDO 将带有一些值的表单插入到 MySQL 数据库中。
/*** Values for the form ***/
$date = date_create();
$time = date('Y-m-d H:i:s');
$message = $_POST['message'];
$uid = $_SESSION['SESS_MEMBER_ID'];
$admin = 1;
/*** prepare the SQL statement ***/
$stmt = $db->prepare("INSERT INTO messages (message_id, timestamp, uid, admin, read, edited, message) VALUES ('',':time',':uid',':admin','','',':message')");
/*** bind the paramaters ***/
$stmt->bindParam(':time', $time, PDO::PARAM_STR);
$stmt->bindParam(':uid', $uid, PDO::PARAM_STR);
$stmt->bindParam(':admin', $admin, PDO::PARAM_INT, 1);
$stmt->bindParam(':message', $message, PDO::PARAM_STR);
/*** execute the prepared statement ***/
$stmt->execute();
结果是:
一个只设置了 message_id 的空条目,并且消息仍然带有它的占位符 :mesagge
(message_id, timestamp, uid, admin, read, edited, message)
15 | 0000-00-00 00:00:00 | 0 | 0 | 0 | 0 |:bericht
占位符或 INSERT 查询有什么问题?