Ajax Code to run PHP query After Facebook Like Button is Clicked
Posted
by
John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2011-06-22T23:54:03Z
Indexed on
2011/06/23
0:23 UTC
Read the original article
Hit count: 126
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!";
}
© Stack Overflow or respective owner