Jump to content

Why Are Some Users Not Saved In My Db?


lporiginalg

Recommended Posts

Hi there, I am new to the forum was really unsure where to post my thread since I have no idea where the issue in my application is actually coming from. I've put a flash game on facebook as a canvas app. Once a user authorizes my application I grab their name and id and then use the id to check if they already exist in my database. If they do I pull their score otherwise I add them into the db.

 

Every browser and 3 different machines I have tried it on, and with multiple user accounts, it always works. I have never been able to reproduce the issue of the user not getting registered in the db, but facebook shows that about 28 people have authorized my app, but only 13 of them have been registered in the db. Some friends I asked to try the game told me they liked the game, and facebook says they played it, but they do not show up in my apps database. 13 out of 28 captured! It makes me wanna cry cause all those uncaptured users are not getting the proper experience.

 

I'm using Amfphp framework to bridge flash and php. The app is hosted for free on Heroku and uses the free pgsql db they provide.

 

The app can be seen here: http://apps.facebook...wordfighterbeta

 

After the flash loads I call the AS3 API for facebook:

 

import com.facebook.graph.Facebook;
Facebook.init(APP_ID, onInit); //my app id is correctly set
function onInit(result:Object, fail:Object):void {
if (result) {
Facebook.api("/me", getUserInfoHandler, null, "GET");
loggedIn = true;
} else {
resultTxt.text = "In order to save your highscores this app requires facebook authentication.";
loginBtn.label = 'Facebook Login';
loginBtn.addEventListener(MouseEvent.CLICK, handleLoginClick, false, 0, true);
loginBtn.enabled = true;
}
}
//called when they click 'login'
function handleLoginClick(event:MouseEvent):void {
Facebook.login(onLogin);
}
function onLogin(result:Object, fail:Object):void {
if (result) {
Facebook.api("/me", getUserInfoHandler, null, "GET");
} else {
resultTxt.text = "Authorization denied.";
}
}

function getUserInfoHandler(result:Object, fail:Object):void {
if (result) {
userName = result.name;
userID = result.id;
registerUser(userID, userName); //this is where I try to add the user to the database

} else {
resultTxt.text = 'fail';
}
}

function registerUser(id, user):void {
if (! local) {
_netConnection = new NetConnection();
_netConnection.connect("https://sheltered-plateau-6639.herokuapp.com/Amfphp/");
_netConnection.call("WordFighter/registerUser", new Responder(handleResultArray, null), id,user);
}
}

function handleResultArray(result:*):void {
for each (var user:Object in result) {
userScore = user.score;
 //start the game
}

 

And here is the registerUser function I wrote in PHP:

 

public function registerUser($id, $name){

 $host = "ec2-107-22-161-45.compute-1.amazonaws.com";
 $user = "jytgyzybpoqjed";
 $pass = "password";
 $db = "dbvgstj2v06pit";
 $con = pg_connect("host=$host dbname=$db user=$user password=$pass") or die ("Could not connect to server\n");
 $query = "SELECT * FROM noobs WHERE fbID='$id'";
 $rs = pg_query($con, $query) or die("Cannot execute query: $query\n");

 if(pg_num_rows($rs) > 0){
  $noobs = array();
  $noobs[] = pg_fetch_assoc($rs);
  return $noobs;
 } else {
  $query = "INSERT INTO noobs (fbID, name, score) VALUES ('$id', '$name', '0')";
  $rs = pg_query($query) or die("Cannot execute query: $query\n");
  $query = "SELECT * FROM noobs WHERE fbID='$id'";
  $rs = pg_query($query) or die("Cannot execute query: $query\n");
  $noobs = array();
  $noobs[] = pg_fetch_assoc($rs);
  return $noobs;
 }

 pg_close($con);
}

 

So yea. Who is the genius out there that can tell me why so many users aren't getting saved. The part that really confuses me is that when I look at the actionscript I see no way they can advance and play the game without the php returning an answer to the registerUser call since that's the only place in the code that starts the game, so why are some people playing the game and evading the database?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.