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.

32 lines
1006 B

пре 3 година
  1. <?php
  2. require_once "pdo.php";
  3. session_start();
  4. if(isset($_POST['comment'])&&isset($_POST['id'])&&isset($_POST['article_id']))
  5. {
  6. if (strlen($_POST['comment']) < 1 ) {
  7. $_SESSION['error'] = '输入不能为空';
  8. header( 'Location: view.php?article_id='.$_POST['article_id']) ;
  9. return;
  10. }
  11. $sql = "INSERT INTO commentsss (comment_id,article_id,name,user_id,content)
  12. VALUES (:comment_id,:article_id,:name,:user_id,:comment)";
  13. $stmt = $pdo->prepare($sql);
  14. try{
  15. $stmt->execute(array(
  16. ':comment_id' => $_POST['id'],
  17. ':article_id' => $_POST['article_id'],
  18. ':name' => $_SESSION['name'],
  19. ':user_id' => $_SESSION['user_id'],
  20. ':comment' => $_POST['comment']
  21. ));
  22. }catch (Exception $e) {
  23. $_SESSION['error'] = '非法';
  24. header( 'Location:view.php?article_id='.$_POST['article_id'] ) ;
  25. return;
  26. }
  27. $_SESSION['success'] = 'Record Added';
  28. header( 'Location: view.php?article_id='.$_POST['article_id']) ;
  29. return;
  30. }