I'm trying to make a very simple Like/Unlike button in PHP (where the page does NOT refresh) I know there are countless tutorials on this but because I am completely new to ajax & jquery, I can't figure out how to implement them (in what file does which part of the code go etc). I have a database of userid's and a new database of user likes. I've gotten this far:
<?php
if (!loggedin()) {
echo 'Please login or register to fave games';
} else {
$gameNum = $GAMES_REPOSITORY[$this_game][num];
$qry = mysql_query("SELECT * FROM fave_games WHERE gamenum='".$gameNum."' AND userid='".$_SESSION[userID]."'");
if (mysql_num_rows($qry)==0) {
# print button to fave
echo 'You haven\'t liked this';
} else {
# print button to unfave
echo 'You\'ve liked this';
}
}
?>
This works, and it manages to check if the user has liked the page/game before or not. And I know I can figure out the last steps, which would be inserting or deleting the like/unlike into the database. I just can't figure out the middle bit, where ajax and jquery come in to make the text buttons and where to code their function... Any help would be greatly appreciated.