Ajax Code to run PHP query After Facebook Like Button is Clicked
- by John
I have the PHP below on a file called fblike.php. On another file, I have the Facebook Like button. The Like button functions. I would like to run the code below when the Facebook Like button is clicked.
I know that FB.Event.subscribe('edge.create', function(response) {} is supposed to run whenever the Like button is clicked. I know that I am probably supposed to use Javascript and maybe Ajax to cause the PHP on fblike.php to run.
But after multiple tries, I can't get it to work. What is the specific Ajax code that I could include within the Facebook Event? Do I need to do anything to the Like button code to allow the Facebook Event to work?
$submissionid = $_POST['submissionid'];
$uid = $_POST['uid'];
mysql_connect("server", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$q = "INSERT INTO fblikes VALUES (NULL, '$submissionid', '$uid', NULL)";
$r = mysql_query($q);
if($r)
{
echo "Success!";
}
elseif(!$r)
{
echo "Failed!";
}