NoteOnMe博客平台搭建
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
1006 B

<?php
require_once "pdo.php";
session_start();
if(isset($_POST['comment'])&&isset($_POST['id'])&&isset($_POST['article_id']))
{
if (strlen($_POST['comment']) < 1 ) {
$_SESSION['error'] = '输入不能为空';
header( 'Location: view.php?article_id='.$_POST['article_id']) ;
return;
}
$sql = "INSERT INTO commentsss (comment_id,article_id,name,user_id,content)
VALUES (:comment_id,:article_id,:name,:user_id,:comment)";
$stmt = $pdo->prepare($sql);
try{
$stmt->execute(array(
':comment_id' => $_POST['id'],
':article_id' => $_POST['article_id'],
':name' => $_SESSION['name'],
':user_id' => $_SESSION['user_id'],
':comment' => $_POST['comment']
));
}catch (Exception $e) {
$_SESSION['error'] = '非法';
header( 'Location:view.php?article_id='.$_POST['article_id'] ) ;
return;
}
$_SESSION['success'] = 'Record Added';
header( 'Location: view.php?article_id='.$_POST['article_id']) ;
return;
}