I am trying to write some data to a MySQL Table however the .post call is returning with a 500 server error. Any help in the right direction would be great.
I think it's something to do with the _POST variables not sending right.
Here is the code:
JS:
function write_table(response) {
var data = {
'user_id' : response.id,
'user_email' : response.email,
'user_first' : response.first_name,
'user_last' : response.last_name
};
console.log(data);
$.ajax({
'url': './includes/php/login_facebook.php',
'data': data,
'type': 'POST',
'beforeSend': function(xhr, settings) {
console.log('ABOUT TO SEND');
},
'success': function(result, status_code, xhr) {
console.log('SUCCESS!');
},
'complete': function(xhr, text_status) {
console.log('Done.');
},
'error': function(xhr, text_status, error_thrown) {
console.log('ERROR!', text_status, error_thrown);
}
});
}
PHP:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$host = 'localhost';
$un = 'root';
$pw = 'root';
$db = 'bikelouis';
$user_id = $_POST['user_id'];
$user_email = $_POST['user_email'];
$user_first = $_POST['user_first'];
$user_last = $_POST['user_last'];
$conn = mysql_connect($host, $un, $pw) or die(mysql_error());
if ($conn) {
echo '<script> alert("connected!");</script>';
mysql_select_db($db) or die(mysql_error());
$sql = "INSERT INTO users (user_id, user_email, user_first, user_last) VALUES ($user_id, $user_email, $user_first, $user_last)";
} else {
echo 'Connection failed.';
}
?>
I am using facebook connect, that is where 'response' is coming from. That works perfectly.