my_collect_post.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../hostsetting/function.php';
  6. require_once "../ucenter/active.php";
  7. $respond=array("status"=>0,"message"=>"");
  8. if(!isset($_COOKIE["userid"])){
  9. #不登录不能新建
  10. $respond['status']=1;
  11. $respond['message']="no power create article";
  12. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  13. exit;
  14. }
  15. add_edit_event(_COLLECTION_EDIT_,$_POST["id"]);
  16. PDO_Connect(_FILE_DB_USER_ARTICLE_);
  17. $query="UPDATE collect SET title = ? , subtitle = ? , summary = ?, article_list = ? , status = ? , lang = ? , receive_time= ? , modify_time= ? where id = ? ";
  18. $sth = $PDO->prepare($query);
  19. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_POST["article_list"] , $_POST["status"] , $_POST["lang"] , mTime() , mTime() , $_POST["id"]));
  20. $respond=array("status"=>0,"message"=>"");
  21. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  22. $error = PDO_ErrorInfo();
  23. $respond['status']=1;
  24. $respond['message']=$error[2];
  25. }
  26. else{
  27. # 更新 article_list 表
  28. $query = "DELETE FROM article_list WHERE collect_id = ? ";
  29. PDO_Execute($query,array($_POST["id"]));
  30. $arrList = json_decode($_POST["article_list"]);
  31. if(count($arrList)>0){
  32. /* 开始一个事务,关闭自动提交 */
  33. $PDO->beginTransaction();
  34. $query = "INSERT INTO article_list (collect_id, article_id,level,title) VALUES ( ?, ?, ? , ? )";
  35. $sth = $PDO->prepare($query);
  36. foreach ($arrList as $row) {
  37. $sth->execute(array($_POST["id"],$row->article,$row->level,$row->title));
  38. }
  39. $PDO->commit();
  40. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  41. /* 识别错误且回滚更改 */
  42. $PDO->rollBack();
  43. $error = PDO_ErrorInfo();
  44. $respond['status']=1;
  45. $respond['message']=$error[2];
  46. }
  47. }
  48. }
  49. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  50. ?>