LoadVars from PHP

OK, I am trying to do my first simple user authentication for a test built in Flash. I’m just checking to see if someone with the same name and email exists in the mySQL database and then echoing out entryAllowed=false if they exist.

PHP Code:
 
//query is successful and these vars trace out in flash
$visitCheck = mysql_query("SELECT entryAllowed,firstName,lastName FROM table WHERE firstName='$postVars_firstName' AND lastName='$postVars_lastName' AND email='$postVars_email' ORDER BY lastName");
while ($row = mysql_fetch_assoc($visitCheck)) {
   foreach($row as $key => $value){
      echo '&'.$key.' = '.$value.'&';
   }
}

Then in Flash…

 
AS 2.0 Code:
var recordStatus:LoadVars = new LoadVars();
recordStatus._parent = this;
recordStatus.onLoad = function(success){
   removeMovieClip(this._parent.sendingHolder_mc);
   trace("recordStatus onLoad");
   if(success){
      for(x in this){
         //THIS TRACES OUT THE VARS ECHOED FROM PHP!!
         trace(x+"="+this[x]);
      } 
      trace("record check successful");
      //THESE ARE ALL UNDEFINED!!
      trace("this.entryAllowed = "+this.entryAllowed);
      trace("this.firstName = "+this.firstName);
      trace("this.lastName = "+this.lastName);
      if(this.entryAllowed != "false"){
         //allow entry
      }else{
         //don't allow entry
      }
   }
}

The AS traces out:

recordStatus onLoad
lastName = close
firstName = mike
entryAllowed = false
onLoad=[type Function]
_parent=_level0.loginHolder_mc.login_mc
record check successful
this.entryAllowed = undefined
this.firstName = undefined
this.lastName = undefined
entry was allowed by record check

I’ve tried banging my head against the keyboard but that didn’t work. Any help would be greatly appreciated!!!

-mike

The problem was solved in the PHP code, but I’m still not sure exactly what it was. Since I was only dealing with a single row, I took the while loop out. And, since I only cared about one column, I took the foreach loop out.

PHP Code:
 
//query is successful and these vars trace out in flash
$visitCheck = mysql_query("SELECT entryAllowed,firstName,lastName FROM table WHERE firstName='$postVars_firstName' AND lastName='$postVars_lastName' AND email='$postVars_email' ORDER BY lastName");
//HERE'S WHAT I CHANGED
if($row = mysql_fetch_assoc($visitCheck)){
    echo '&entryAllowed='.$row['entryAllowed'].'&';
    }else{
      echo '&entryAllowed=true&';
    }
}

I left the Flash code alone. The lesson learned was…


//varables echoed out of PHP using this:
$row = mysql_fetch_assoc($visitCheck)){
foreach($row as $key => $value){
   echo '&'.$key.' = '.$value.'&';
}
 
//weren't directly accessible in my Flash loadVars object, but this was:
$row = mysql_fetch_assoc($visitCheck)){
echo '&entryAllowed='.$row['entryAllowed'].'&';

The original problem was that my loadVars object could see the variables from PHP in the ‘for in loop’, but not immediately after when accessed directly. I’m still baffled as to why these differences in the PHP code would effect Flash, but it’s working… for now… I don’t know what I’ll do when I need to get more than one row.

-mike