I am trying to use Ajax to insert two variables into MySQL when a user clicks the Facebook like button. Nothing is being put into the database table The code I'm using is below. Any ideas why nothing is being put into the database tables?
Thank in advance,
John
On file with Facebook Like button:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script >
FB.Event.subscribe('edge.create', function(response) {
$.ajax({
url: "fblike.php", // the url of your php script
context: document.body,
success: function(){
// if you want something to be executed when a result comes back
}
});
});
</script>
<?php
session_start();
$uid = $_SESSION['loginid'];
$submissionid = mysql_real_escape_string($_GET['submissionid']);
$_SESSION['submissionid'] = $submissionid;
echo '<div id="fb-root"></div>';
echo "<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
echo '</script>";
echo '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">';
echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="" send="true" layout="button_count" width="450" show_faces="false" font="arial"></fb:like>';
php?>
On fblikephp:
<?php
session_start();
$uid = $_SESSION['loginid'];
$submissionid = $_SESSION['submissionid'];
mysql_connect("host", "user", "pw") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
mysql_query("INSERT INTO fblikes VALUES (NULL, '$submissionid', '$uid', NULL)");
?>
<html><head/><body/></html>and so on. then add an alert to your success function to see if you are making a correct ajax call first. then i can give you more details depending on the results