Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. public function uploadPost($title,$image){
  2. try{
  3.  
  4. if(isset($_SESSION['user_session'])){
  5. $user_id = $_SESSION['user_session'];
  6.  
  7. $stmt = $this->runQuery("SELECT * FROM users WHERE id=:id");
  8. $stmt->execute(array(":id"=>$user_id));
  9.  
  10. $myRow=$stmt->fetch(PDO::FETCH_ASSOC);
  11.  
  12. }else{
  13. $_SESSION["error"]='<div class="alert alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Sorry, You have to login in your profile!</div>';
  14. echo $_SESSION["error"];
  15. exit();
  16. }
  17.  
  18. $addedby = $myRow['id'];
  19.  
  20. $stmt = $this->conn->prepare("INSERT INTO fun_posts(title,image,addedby) VALUES(:title, :image, :addedby)");
  21.  
  22. $stmt->bindparam(":title", $title);
  23. $stmt->bindparam(":image", $image);
  24. $stmt->bindparam(":addedby", $addedby);
  25.  
  26. $stmt->execute();
  27.  
  28. $_SESSION["result"]='<div class="alert alert-success alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>You have succesfully uploaded new post!</div>';
  29. echo $_SESSION["result"];
  30. exit();
  31.  
  32. }
  33. catch(PDOException $e)
  34. {
  35. echo $e->getMessage();
  36. }
  37. }
  38.  
  39. public function insertAction($action, $addedby, $follow, $unfollow, $comment, $reply, $likecomment,
  40. $likepost, $addimage, $addpost){
  41. try{
  42.  
  43. $stmt = $this->conn->prepare("INSERT INTO user_actions(action,addedby,follow,unfollow,comment,reply,
  44. likecomment,likepost,addimage,addpost) VALUES(:action, :addedby, :follow, :unfollow, :comment, :reply,
  45. :likecomment, :likepost, :addimage, :addpost)");
  46.  
  47. $stmt->bindparam(":action", $action);
  48. $stmt->bindparam(":addedby", $addedby);
  49. $stmt->bindparam(":follow", $follow);
  50. $stmt->bindparam(":unfollow", $unfollow);
  51. $stmt->bindparam(":comment", $comment);
  52. $stmt->bindparam(":reply", $reply);
  53. $stmt->bindparam(":likecomment", $likecomment);
  54. $stmt->bindparam(":likepost", $likepost);
  55. $stmt->bindparam(":addimage", $addimage);
  56. $stmt->bindparam(":addpost", $addpost);
  57.  
  58. $stmt->execute();
  59.  
  60. $_SESSION["result"]='<div class="alert alert-success alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Action has been succesfully inserted!</div>';
  61. echo $_SESSION["result"];
  62. exit();
  63.  
  64. }
  65. catch(PDOException $e)
  66. {
  67. echo $e->getMessage();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement