Standard disclaimer--I am brand new to coding and I have never used a MySQL database before. I also do not know PHP (I know that many of the answers on this site include using it). I do know how to use node.js (as much as I know how to use any of this...)
What I'd like to do: Have a simple "like" feature that displays how many users have liked an event. I know how to write an onclick function, so right know the likes are increasing--but I need to link it to my database so that number of likes pulls through from one session to the next.
This is my database schema:
CREATE TABLE `likes` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`likeCounter` INT(11) NULL DEFAULT '0',
PRIMARY KEY (`id`))
This is my jQuery code:
$(document).ready(function() {
// counter variable
var counter = 0;
// connect to mysql
var mysql = require("mysql");
// create the connection information for the sql database
var connection = mysql.createConnection({
host: "localhost",
port: 3306,
// Your username
user: "root",
// Your password
password: "root",
database: "quickiehelp"
});
// connect to the mysql server and sql database
connection.connect(function(err) {
if (err) throw err;
// run the start function after the connection is made to prompt the user
start();
// counter function
function heartClick() {
counter++;
$('.clicks').html(counter);
$"counter" = mysql_query("UPDATE `likes` SET `likeCounter");
}
$('#heartContainer').click(function(){
console.log("alert");
heartClick();
$('#heartContainer').toggleClass("animated pulse");
});
});