Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
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.

vote.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once('config.php');
  3. //check to see that the form has been submitted
  4. $id = 0;
  5. $vote = "";
  6. $points = 0;
  7. if(isset($_POST) && $logged_in)
  8. {
  9. $user_id = $user->id;
  10. $id = rawurldecode($_POST['id']);
  11. $table = rawurldecode($_POST['table']);
  12. $points = rawurldecode($_POST['vote']);
  13. $user_vote = $db->select('votes', 'table_name=? AND row_id=? AND user_id=? ORDER BY id DESC LIMIT 1', array($table, $id, $user_id));
  14. if ($user_vote)
  15. {
  16. $old_points = $user_vote['points'];
  17. if ($old_points != $points)
  18. {
  19. $points = $old_points + $points;
  20. }
  21. $data = array(
  22. "points" => $points
  23. );
  24. //update the row in the database
  25. $db->update($data, 'votes', 'id=?', array($user_vote['id']));
  26. }
  27. else
  28. {
  29. $data = array(
  30. "table_name" => $table,
  31. "row_id" => $id,
  32. "user_id" => $user_id,
  33. "points" => $points
  34. );
  35. $db->insert($data, 'votes');
  36. }
  37. $results = $db->select('votes', 'table_name=? AND row_id=?', array($table, $id), 'sum(points) totalPoints');
  38. $votes = $results['totalPoints'];
  39. echo $votes;
  40. }
  41. else
  42. {
  43. echo "false";
  44. }
  45. ?>