代码
if(isset($_POST['post_comment_submit'])){
//Get all values
$uid = $_SESSION['user']['id'];
$pid = $_POST['pid'];
$rid = $_POST['rid'];
$cmt = $_POST['post_reply_content'];
$date = date('c');
//Check that comment is not empty
if(empty($cmt)){
header('location: ../post.php?id='.$pid.'&error=incomplete');
exit;
}
//Connect to database
include "../inc/connect.php";
//Prepare statement
$stmt = $dbh->prepare("INSERT INTO `post_comments` (`user_id`,`post_id`,`reply_id`,`comment`,`date`) VALUES (:uid, :pid, :rid :cmt, :date)");
//Bind values
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":pid", $pid);
$stmt->bindParam(":rid", $rid);
$stmt->bindParam(":cmt", $cmt);
$stmt->bindParam(":date", $date);
//Execute
if($stmt->execute()){
header('Location: ../post.php?id='.$pid);
} else {
print_r("Error");
echo "<br>";
print_r($stmt);
echo "<br>";
print_r($_POST);
echo "<br>";
}
}
输出
Error
PDOStatement Object ( [queryString] => INSERT INTO `post_comments` (`user_id`,`post_id`,`reply_id`,`comment`,`date`) VALUES (:uid, :pid, :rid :cmt, :date) )
Array ( [pid] => 8 [rid] => 1 [post_reply_content] => Test Comment Reply [post_comment_submit] => Add comment )
解释
这是PHP
处理来自表单的数据的页面。该功能是通过输入用户ID、帖子ID、要回复的评论ID、评论内容和评论的日期/时间来处理对页面评论的回复。
问题
如您所见,该PHP
文件正在接收所有相关$_POST
数据,但由于某种原因,SQLINSERT
命令未处理。