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.

47 lines
1.8 KiB

3 years ago
  1. <?php
  2. require_once "pdo.php";
  3. session_start();
  4. if ( isset($_POST['article']) && isset($_SESSION['user_id']) && isset($_POST['title'])&&isset($_POST['article_type'])) {
  5. if ( isset($_POST['article_id']) &&$_POST['article_id']!=null){
  6. $sql = "UPDATE article SET content=:articles,headline=:headline,category=:category,public=:public WHERE article_id = :id ";
  7. $stmt = $pdo->prepare($sql);
  8. try{
  9. $stmt->execute(array(
  10. ':articles' => $_POST['article'],
  11. ':headline' => $_POST['title'],
  12. ':public' => $_POST['article_type'],
  13. ':id'=>$_POST['article_id'],
  14. ':category'=>$_POST['category']
  15. ));
  16. }catch (Exception $e) {
  17. $_SESSION['error'] = 'fail';
  18. header( 'Location: edit_article.php' ) ;
  19. return;
  20. }
  21. $id=$_POST['article_id'];
  22. }
  23. else{
  24. $sql = "INSERT INTO article (content,user_id,headline,public,category,viewer) VALUES (:articles, :user_id,:headline,:public,:category,:viwer)";
  25. $stmt = $pdo->prepare($sql);
  26. try{
  27. $stmt->execute(array(
  28. ':articles' => $_POST['article'],
  29. ':user_id' => $_SESSION['user_id'],
  30. ':headline' => $_POST['title'],
  31. 'viwer'=>0,
  32. ':public' => $_POST['article_type'],
  33. ':category'=>$_POST['category']
  34. ));
  35. }catch (Exception $e) {
  36. $_SESSION['error'] = 'fail';
  37. header( 'Location: edit_article.php' ) ;
  38. return;
  39. }
  40. $id=$pdo->lastInsertId();
  41. }
  42. $_SESSION['success'] = '保存成功';
  43. header( 'Location:view.php?article_id='.$id ) ;
  44. return;
  45. }