1

So, I'm currently using a Facebook login button API. What I wanted to do was for my code to add the user's email after the user logged in, into the SQL database. I'm having trouble understanding how to access the information of the email in the PHP code. This is all done on an HTML page but the HTML page doesn't hold variables and I tried running the javascript function to no avail. Part of my code is

 function returnEmail() {
    var url = '/me?fields=name,email';
    var email = '';
    FB.api(url, function(response) {
    console.log('Successful calls email function');
    email = response.email;   
    });
    return email;
 }

This essentially returns a string variable that represents the email value. I'm not familiar enough with PHP and how it interacts with Javascript to understand how I can get that email information and then add it. Thanks if you can provide any help!

James Lee
  • 11
  • 1
  • 2
    PHP does not really interact with Javascript as PHP runs on the server and Javascript runs in the browser. By using Ajax you can send variables to php and receive the response, alternatively use php to generate javascript code/variables. – Professor Abronsius Jan 18 '16 at 08:23
  • 1
    Possible duplicate of [Data transfer from JavaScript to PHP](http://stackoverflow.com/questions/3072817/data-transfer-from-javascript-to-php) – Alessandro Da Rugna Jan 18 '16 at 08:41
  • Thanks guys for the help! I used Ajax to do this – James Lee Jan 29 '16 at 19:43

0 Answers0