Skip navigation
Jusmark123
Currently Being Moderated

PHP returning "undefined" variable to flash

Apr 25, 2012 4:33 AM

Tags: #php #as3 #flash_professional #php/mysql #urlvariables

Hello Everyone, I am working on a touch screen POS login interface that takes in a four digit user pin and searches a database. It uses Flash, PHP and MYSQL. I need PHP to return the user name and access level. The AS3 code below is what I have so far, but it doesn't work correctly.

 

"IntLogin" is the 4 digit pin that is sent to PHP when the user touches login on the GUI.

 

function onLoginClick(e:MouseEvent):void

{

          keyLogin.gotoAndStop("KeyDn");

 

          var loader:URLLoader = new URLLoader();

          var request:URLRequest = new URLRequest("Login.php");

          var variables:URLVariables = new URLVariables();

 

          loader.dataFormat = URLLoaderDataFormat.VARIABLES;

          request.method = URLRequestMethod.POST;

          variables.login = intLogin;

 

          request.data = variables;

          trace(request.data = variables);

 

          loader.addEventListener(Event.COMPLETE, onComplete);

          loader.load(request);

 

           function onComplete(event:Event):void{

                    var loader:URLLoader = URLLoader(event.target);

                    var variables:URLVariables = new URLVariables(loader.data);

 

                    txtUser.text = variables.username;

 

Next is the PHP code which works great in the browser when I implictly give $select a value, returning "username=Walker&access=1"

However, when I run the program from Flash it returns an undefined variable and the end of the PHP file.

 

<?php # Login.php

 

 

require_once ('mysqli_connect.php');

//Connect to the db

 

 

if (!empty($_POST['login'])){

          $select = $_POST['login'];

 

          $sql = "SELECT Last_Name AS name, Access_Level AS level FROM Users WHERE User_ID = '$select'";

 

          $q = mysqli_query($dbc, $sql);

 

 

          if($q){

 

                    $row = mysqli_fetch_array($q, MYSQLI_ASSOC);

 

                    $name = $row['name'];

 

                    $access = $row['level'];

 

                    echo "username=$name";

  echo "&access=access";

          }

 

}

?>

 

I have have tried debugging the both the PHP and the AS code, but I am stuck. When I trace in AS3 I get the following:

 

1445

login=1445

undefined

$access";

          }

 

}

?>

 

Please if you anyone can help with this it would be greatly appreciated. I am on a strict timeline and I don't know what to do here.

 

Thanks:)

 

Jusmark

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points