all groups > flash data integration > april 2007 >
You're in the

flash data integration

group:

New to PHP


New to PHP aniebel
4/9/2007 7:36:47 PM
flash data integration:
I'm reading David Powers' book on Flash and PHP5. So far I feel like it's been
very helpful but there are apparently a few things I am not getting my head
around.

Trying to modify a sessions login script using AS2.0, PHP5 and mySQL5. My
problem is that I'm getting an undefined session variable back from the PHP
script. Can someone give me some guidance as to how and where I'd place
something in PHP to test (via trace?) if things are getting done? If I manually
place the login variables (username and pw), and test the PHP script in a
browser, it's fine. It's just with Flash that I'm having problems.



//IN FLASH//
function checkDetails():Void {
// this gathers the form input and sends it to the PHP script and clear any
error messages
error_txt.text = "";
loginDets.username = userName_txt.text;
loginDets.pwd = pwd_txt.text;

loginDets.sendAndLoad("http://localhost/~Amy/phpflash/tagPhoneList/processLogin
..php?ck="+new Date().getTime(), loginResponse);
}
function doLogin():Void {
trace(this.test);
if (this.authenticated == "ok") {
trace("authenticated");
// if login details OK, load protected page
getURL("http://localhost/~Amy/phpflash/tagPhoneList/registerManagement.php");
} else {
// otherwise display error message
error_txt.text = "Sorry, access denied.";
}
}
// assign event handler to login button
submit_btn.onRelease = checkDetails;
// create LoadVars instances to send and receive data
var loginDets:LoadVars = new LoadVars();
var loginResponse:LoadVars = new LoadVars();
loginResponse.onLoad = doLogin;
// set color for text input field borders
userName_txt.borderColor = 0x7C756C;
userName_txt.tabEnabled = true;
userName_txt.tabIndex = 1;
pwd_txt.borderColor = 0x7C756C;
pwd_txt.password = true;
pwd_txt.tabEnabled = true;
pwd_txt.tabIndex = 2;
Selection.setFocus("userName_txt");
// initialize error message text area
this.createTextField("error_txt", this.getNextHighestDepth(), 50, 60, 400, 25);
// set the text format for the error message area and apply it
var errorFormat:TextFormat = new TextFormat();
errorFormat.bold = true;
errorFormat.color = 0x7C756C;
errorFormat.font = "Arial,Helvetica,_sans";
errorFormat.size = 18;
errorFormat.align = "center";
error_txt.setNewTextFormat(errorFormat);

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
checkDetails();
//trace("enter pressed");
}
};
Key.addListener(keyListener);
stop();
//
//IN PHP//
<?php
// check correct variables have been received through the POST array
if (isset($_POST['username']) && isset($_POST['pwd'])) {

// initiate the session
session_start();
// include the Database classes
require_once('../classes/database_mysqli.php');

// escape quotes and apostrophes if magic_quotes_gpc off
foreach($_POST as $key=>$value) {
if (!get_magic_quotes_gpc()) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}
}

// create a Database instance and check username and password
$db = new Database('localhost','myUN','mypassword','myDB');
$sql = 'SELECT * FROM users WHERE userName = "'.$_POST['username'].'"
AND password = "'.sha1($_POST['pwd']).'"';
$result = $db->query($sql);


// if a match is found, approve entry; otherwise reject
if ($result->num_rows > 0) {

$_SESSION['authenticated'] = $_POST['username'];
echo 'authenticated=ok';
}
else {
echo 'authenticated=getLost';
}


// close the database connection
$db->close();
}
?>
//
//mySQL has 3 columns... primaryKey, userName and password//
Re: New to PHP MotionMaker
4/9/2007 7:47:25 PM
Your script returns the url vars
authenticated=ok
or
authenticated=getLoad
This is based on a match in the database and not on the _SESSION system in PHP.
Thus the SELECT statement is not matching. So that could mean the data you are
sending to the PHP script is not getting there, spelled differently or is not
found in the database. Also the SQL statement could be invalid and failing from
anyting from the database not being connect to tables not there to login
failure.

You may consider testing the SQL statement in something like PHPAdmin to see
if it is valid.

But a great way to "SEE" is to create a simple HTML form with the data
variables and have them send to the PHP script and be sure the PHP is echoing
the error statements.
Re: New to PHP aniebel
4/9/2007 7:53:26 PM
Re: New to PHP aniebel
4/9/2007 8:01:35 PM
Yikes, one more thing. This is why I'm puzzled and I forgot to mention this. If
I change the conditional statement in PHP to the following, I still get
undefined.


// if a match is found, approve entry; otherwise reject
if ($result->num_rows > 0) {

$_SESSION['authenticated'] = $_POST['username'];
echo 'authenticated=ok';
}
else {
//just to see, I changed this to also say "ok"
echo 'authenticated=ok';
}
Re: New to PHP MotionMaker
4/9/2007 8:24:43 PM
Then perhaps this line is failing
if (isset($_POST['username']) && isset($_POST['pwd'])) {
I do not see how if the Flash send LoadVars is working and appears to have the
same variable names with the same case.

Generally is use $_REQUEST but I see others use $_POST as well.

Again a simple HTML form might help reveal where the PHP script is failing.
With that approach you can add more echo statements for debugging.


Re: New to PHP aniebel
4/9/2007 8:26:59 PM
AddThis Social Bookmark Button