Hi all,
I am trying to run a database insert of the facebook user details into my MySQL db. The script below runs on the basis that the facebook user is not in the database. We then run an insert, on that being a success we run a select and create the session details.
The problem is that the update query does not work - the first select returns no data (although when I echo it out isays there is data?) as the user is not in the database. On this basis it should insert the details into the user tables:
if ($user){
//get user basic description
$userInfo = $facebook->api("/$user");
$email = $userInfo['email'];
$name = $userInfo['name'];
$gender = $userInfo['gender'];
$oauth_uid = $user;
$query1 = "SELECT userid, email FROM users WHERE oauth_uid = '$oauth_uid'";
$result1 = mysql_query($query1);
$row = mysql_fetch_assoc($result1);
if (empty ($result1)){
echo "result1 is empty";
$oauth_provider = 'facebook';
$query2 = "INSERT INTO users (oauth_provider, oauthid, name, email) VALUES ($oauth_provider, $oauth_uid, $name, $email)";
$result2 = mysql_query($query2);
}
else{
echo "result1 has data";
$oauth_provider = 'facebook';
$query2 = "INSERT INTO users (oauth_provider, oauthid, name, email) VALUES ($oauth_provider, $oauth_uid, $name, $email)";
$result2 = mysql_query($query2);
// echo "oauth: $oauth_provider";
}
if (empty ($result2)){
echo "query2 is empty";
}
else{
echo "query2 has data";
$query3 = "SELECT userid, email FROM users WHERE oauth_uid = '$oauth_uid'";
$result3 = mysql_query($query3);
}
Query 1 echos out:
query: SELECT userid, email FROM users WHERE oauth_uid = '1xxxxxxxxxxx'
result 1: has data in it when I echo that out.
Query 2 echos out:
query 2: INSERT INTO users (oauth_provider, oauthid, name, email) VALUES (facebook, 10xxxxxxxxxxxxx, Fred James, xxx@acme.com)
This insert is not working, when I look at the users table there is no data in there. What am I missing?