comments.php 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. include "../path.php";
  3. include "./_pdo.php";
  4. if(isset($_POST["album"])){
  5. $album=$_POST["album"];
  6. }
  7. else{
  8. echo "no album id";
  9. exit;
  10. }
  11. if(isset($_POST["book"])){
  12. $book=$_POST["book"];
  13. }
  14. else{
  15. echo "no book id";
  16. exit;
  17. }
  18. if(isset($_POST["paragraph"])){
  19. $paragraph=$_POST["paragraph"];
  20. }
  21. else{
  22. echo "no paragraph id";
  23. exit;
  24. }
  25. if(isset($_POST["text"])){
  26. $text=$_POST["text"];
  27. }
  28. else{
  29. echo "no text";
  30. exit;
  31. }
  32. $db_file = _FILE_DB_COMMENTS_;
  33. PDO_Connect("sqlite:$db_file");
  34. // 开始一个事务,关闭自动提交
  35. $PDO->beginTransaction();
  36. $query="INSERT INTO comments ('id','album','book','paragraph','text','user','time') VALUES (NULL,?,?,?,?,?,?)";
  37. $stmt = $PDO->prepare($query);
  38. $newData=array($album,$book,$paragraph,$text,4,time());
  39. $stmt->execute($newData);
  40. // 提交更改
  41. $PDO->commit();
  42. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  43. $error = PDO_ErrorInfo();
  44. echo "error - $error[2] <br>";
  45. }
  46. else{
  47. echo "updata 1 recorders.";
  48. }
  49. ?>