I am having a real problem here and have tried multiple ways to code this, but nothing is working.. I am working on a small facebook app for a non-profit and the very first thing I need to do on the index page is to pull the facebook uid into my database. (Oh, I am using PHP4 and MySQL 4.1.18)
I have created the following code:
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
if ($action == "ADD") {
$sql = 'SELECT COUNT(userID) FROM `table1` WHERE userID=$user';
mysql_select_db($database, $connection);
$result=mysql_query($sql, $connection) or die(mysql_error());
$theCount=$result[0];
if ($theCount == 0) {
$insertSQL="INSERT INTO `table1`(userID) VALUES($user)";
mysql_select_db($database, $connection);
$result2=mysql_query($insertSQL, $connection) or die(mysql_error());
}
if ($theCount == 1) {
$updateSQL="UPDATE `table1` SET money=money+50 WHERE userID=$user";
mysql_select_db($database, $connection);
$result3=mysql_query($updateSQL, $connection) or die(mysql_error());
}
}
Now, just so you understand the different things I have done and tested, I have tried if and else instead of both if statements for count. When I had the UPDATE set as "else" and I removed the WHERE part, it did do the update in my database and gave all rows 50 more money, so I know my connection is working well. And then if I add a redirect at the bottom of the page such as this
$facebook->redirect("$canvas_page"."main.php?userID=$user");
it would redirect and show the userID in the URL and everything so I know the $user variable is working, but would not add the userID to the database.
Should I be using if and Else or what can I do to make this work? Facebook does allow us to store uid so that shouldn't be a problem. I am just learning php and mysql (although I do have experience with CF and MSSQL so I'm not new to coding) but I took on this small "should be simple" app for facebook as an effort to learn php and mysql and its not going very well at all. 😕
Thanks for any suggestions, direction, or help!