PDA

View Full Version : admin login works but then it dosen't :*(


Paul Ferrie
01-11-2003, 09:58 PM
Awrighty guys

Right I have built a little user regi and login system
http://www.innovativedesigns.org.uk...ogin/login.html

Which works just fine But as soon as i load it into the main movie It dosen't work.



on (press, release) {
loadMovie("login.swf", _root.loginmc);
_root.loginmc._x = 400;
_root.loginmc._y = 200;
}



I mean when i fill in the fields and hit the submit button it just sits there waiting for a response from the php script that all is clear.

The code in the login.swf

on (release) {
if (!name.length) {
loginT = "Please Enter your name";
} else if (!pass.length) {
loginT = "Please Enter your password";
} else {
loadVariables("php/login.php", this, "POST");
loginT = "Sending...";
gotoAndPlay(3);
}
}


Now in Frame 3 I have a checker that loops until php validates that details

[code]if (CheckLog ne "") {
gotoAndPlay ("logged in");
} else {
gotoAndPlay (2);
][/coe]

Heres the code in the php file

$query = "SELECT name,pass FROM contacts WHERE name='$name' AND pass='$pass'";
$result = mysql_query($query);

/* This just gets the number of rows in the Query - It's just a check to see if the Name exists - If not it prints out an error statement. */
$numR = mysql_num_rows($result);

// If the number of rows is not equal to one then it prints out an error statement - Name not in Database.

if ($numR == 1) {
print "loginT=Login Complete&CheckLog=1";
}
else {
print "loginT=Not found - Please register";
}

?>



Does anyone have any ideas?
Like i said it works alone but don't when it's loaded into the main movie..

cheers

Paul Ferrie
01-11-2003, 11:09 PM
Sorry the url was a bit screwed
http://www.innovativedesigns.org.uk/test/adminlogin/login.html

freddycodes
01-12-2003, 12:43 AM
You using Flash MX or Flash 5?

Paul Ferrie
01-12-2003, 12:32 PM
flashmx

freddycodes
01-12-2003, 07:43 PM
I had to change a few things to get yours to work. One thing I used the new LoadVars() object because its a whole lot easier to detect when the variables have made it back into flash. I attached the flas, because I think it will be easier to understand than me just putting a bunch of code here.

The new code for login.swf is

var myLoginVars = new LoadVars();
myButton.onRelease = function() {
if (!name.length) {
loginT = "Please Enter your name";
}
else if (!pass.length) {
loginT = "Please Enter your password";
}
else {
myLoginVars.name = name;
myLoginVars.pass = name;
//Change the url to fit your needs
myLoginVars.sendAndLoad("http://localhost:8080/mx/login/login.php", myLoginVars, "POST");
myLoginVars.onLoad = checkLogin;
loginT = "Sending...";
}

}
function checkLogin() {
trace (this);
loginT = myLoginVars.retVal;
}


I also change dit so the php script returns a variable named retVal instead of trying to assign loginT a value in the php script.


<?php
$name = $_POST['name'];
$pass = $_POST['pass'];
$db = mysql_connect("localhost", "root", "");
mysql_select_db("test");
$query = "SELECT name,pass FROM contacts WHERE name='$name' AND pass='$pass'";
$result = mysql_query($query);

/* This just gets the number of rows in the Query - It's just a check to see if the Name exists - If not it prints out an error statement. */

// If the number of rows is not equal to one then it prints out an error statement - Name not in Database.

if (mysql_num_rows($result) > 0) {
print "retVal=Login Complete&CheckLog=1";
}
else {
print "retVal=Not found - Please register";
}

?>

Paul Ferrie
01-12-2003, 08:32 PM
Hi m8 cheers for your help and everthing but the login.swf works just fine. The problems start when i load it into my main site and login from there. You are aware of that yes?

freddycodes
01-12-2003, 08:36 PM
I read your post, I included loginTest.flas in my zip file, which shows the login.swf loading into it and still working. Without seeing whats going on in your flas, there is no real way to tell. I would suggest upgrading your script to use LoadVars() instead of loadVariables. It is so much easier to use.

Paul Ferrie
01-12-2003, 08:44 PM
How can that code trace a return if you can't test flash and php in Autherware?


This is new
"myLoginVars.sendAndLoad"
Does this check for a response from the php script?

Paul Ferrie
01-12-2003, 08:54 PM
Is ther any chance u can simplfy the fla. All this new Funtion() stuff is very new to me
Flash4-5 coder

freddycodes
01-12-2003, 09:09 PM
Dude thats pretty darned simplified.

sendAndLoad sends the variables as well as loads new variables from the script.

To see what is making it to PHP I usually use soething like this at the top of my script.


foreach($_POST as $key => $val) {
$data .= "$key = $val\n";
}
$fp = fopen("log.txt", "w");
fputs($fp, $data);
fclose($fp);




How can that code trace a return if you can't test flash and php in Autherware?


What does this mean? Does Authorware refer to the Flash MX program or is it something different? Did you try testing my two movie. Try looking at loginTest.swf in the browser and make sure login.swf has the correct path to your php script.


myLoginVars.onLoad = checkLogin;


This line says to run the function "checkLogin" when a response comes back from the php script.


function checkLogin() {
loginT = myLoginVars.retVal;
}


This just assigns the return variable "retVal" from the php script to the dynamic text box loginT.

freddycodes
01-12-2003, 09:11 PM
Is ther any chance u can simplfy the fla. All this new Funtion() stuff is very new to me
Flash4-5 coder


If you are going to be using Flash MX, I would suggest getting to know the new event handler models. In flash 4/5 you had to put event handlers right on the movie clip instance.

Like say we have a button with an instance name "foo"

The old way is to attach actions directly to the instance.


on (release) {
//do something
}


The new much better way is to use timeline actions


foo.onRelease = function() {
//do something
}


These two do the same but the new way allows you to put the actions in a frame on the timeline.

Paul Ferrie
01-12-2003, 09:22 PM
See All this new coding Macro media introdused with MX i hate!
Like Components
Scrollbar
All that **** in ther
Whats wrong with txtfield++ or --
simply enough and did what it was supposed to do. And whats this u say about getting more code on the timeliune than on the buttons and clips themselves, could u explane that abit more.

Autherware do refer to flash mx testing stage. As long as i have been playing around with Flash 3-4 years there is still a lot i have to uncover.

Cheers And no i have not tested your files yet. If i were too and it worked it would mean a bucket load more work for me to do.
The Damn thing works just not from within another movie
this really sucks since i have waisted 2 days alread with this problem.

freddycodes
01-12-2003, 09:28 PM
Well they made the changes as improvements, you must be a designer, because being a developer IMO these improvements make Flash way better. There is some structure finally. I mean how much easier can it be to add a scrollbar to a text field now. Drag the textfield on to the stage. Give it an instance name, then drag a scrollbar on top of the text field and let go. That is pretty darned easy.

Like I said I cannot tell why yours is not working because I cannot see your implementation only bits and pieces of it.

Frame actions vs object actions, I addressed in my last post.


Autherware do refer to flash mx testing stage. As long as i have been playing around with Flash 3-4 years there is still a lot i have to uncover.



How can that code trace a return if you can't test flash and php in Autherware?


Of course you can as long as you specify the full http:// path to the php script in your LoadVars() object

myLoginVars.sendAndLoad("http://localhost:8080/mx/login/login.php", myLoginVars, "POST");


I am testing the login stuff right now from the Flash MX program.

Paul Ferrie
01-12-2003, 09:35 PM
Does $name = $_POST['name'] make the Vairable 'name' global across my server?

freddycodes
01-12-2003, 09:35 PM
For more on the new event model read this.
http://www.macromedia.com/support/flash/action_scripts/event_methods/

freddycodes
01-12-2003, 09:37 PM
No for security reasons you should never access variables directly, you should always get them from their source, in this case since the method POST was used, we want to get them from the $_POST array.