Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <form action = 'index.php?page=addLike' method = 'POST'>
  2. <input type = 'hidden' name = 'post_id' value = '$post_id'/>
  3. <input type = 'hidden' name = 'user_id' value = '$user_id'/>
  4. <input type = 'submit' value = '' class = 'likeButton'/>
  5. </form>";
  6.  
  7. <?php
  8.  
  9. include_once "models/blogLikes_Table.class.php";
  10. $like = new blogLikes_Table($db);
  11.  
  12. $user_id = $siteVisitor->getId();
  13. $post_id = $_POST['post_id'];
  14.  
  15. $like->insertLike($user_id, $post_id);
  16.  
  17. public function insertLike($user_id, $post_id){
  18. $sql = "INSERT INTO blogLikes (user_id, post_id, value) VALUES ( ?,?,? )";
  19. $statement = $this->db->prepare($sql);
  20. $data = array($user_id, $post_id, "1");
  21. $statement->execute($data);
  22. return $statement;
  23. }
  24.  
  25. $(".likeButton").click(function myCall() {
  26.  
  27. var request = $.ajax({
  28. url: "addLike.php",
  29. type: "GET" ,
  30. data: "html"
  31. });
  32.  
  33. request.done(function(msg) {
  34. alert("this works!!!!!");
  35. });
  36.  
  37. request.fail(function(jqXHR, textStatus) {
  38. alert( "Request failed: " + textStatus );
  39. });
  40. return false;
  41. });
  42.  
  43. var postData = $("#your_form_id").serializeArray();
  44. var request = $.ajax({
  45. url : "addLike.php",
  46. type: "POST",
  47. data : postData
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement