Solved

Flash not sending variables to PHP

Posted on 2003-12-07
6
275 Views
Last Modified: 2010-04-03
I have writtin a php script for a flash user login program however when I try to send the username and password vars to my php page, the script echo's "1" which means that the username and/or password are not in the database. I have put in the correct username and password but it will not work for some reason.
The other thing I need to figure out how to do, is have my php page send the number that has been echoed back to my flash document.
For example, if I was banned from the program, php would echo "2", then that number is read by flash and the appropriate action is taken.
Here is my actionscript:

loginBTN.onRelease = function() {
      status = "Loading...please wait..."
      myUser = new LoadVars()
      myUser.username = _root.username.text
      myUser.pwd = _root.pwd.text
      loadVariablesNum("http://www.website.com/scripts/login.php", myUser, "GET")
      myUser.onLoad = function() {
            if (myUser.status == 0) {
                                                gotoAndStop(10)
            }
            if (myUser.status == 1) {
                                                status = "Incorrect uesrname or password"
            }
            if (myUser.status == 2) {
                  status = "BANNED!"
            }
            if (myUser.status == 3) {
                  status = "Double login."
            } else {
                  status = "Error"
            }
      }
}

Here is my php page:

<?php      
      require_once "db_class.inc.php";
      require ('db.php');
      $connect = mysql_connect($dbhost, $dblogin, $dbpass) or die(mysql_error());
      $db_select = mysql_select_db($dbname) or die(mysql_error());
            $ipq = "SELECT ip FROM ip_ban";
            $ipr = mysql_query($ipq) or die(mysql_error());
                  while($iprow = mysql_fetch_assoc($ipr)) {
                        if($iprow["IP"] == $_ENV["REMOTE_ADDR"]) {
                            echo "&result=2&";
                              exit();
                        }
                  }
            $username = $HTTP_GET_VARS['username'];
            $pwd = $HTTP_GET_VARS['pwd'];
            $query = mysql_query("SELECT * FROM users WHERE username= \"$username\" AND password= \"$pwd\" ");
            if (mysql_num_rows($query) > 0) {
                  echo "&result=0&";
            }  else {
                  echo "&result=1&";
            }
?>


Any help would be great.

Cheers

-OBCT
0
Comment
Question by:OBCT
  • 3
6 Comments
 

Expert Comment

by:DILORENZO
ID: 9905078
Hello, I think you could try

sendandload("http://www.website.com/scripts/login.php", myUser, "POST")

rather than

loadVariablesNum("http://www.website.com/scripts/login.php", myUser, "GET")

..this is where your passing to the php right. If not I don't see where you are.    Try not to use get with sensitive info or it will be visible.
0
 
LVL 9

Author Comment

by:OBCT
ID: 9918189
I tried your suggestion and changed my php to use HTTP_POST_VARS but it still didn't work.
0
 
LVL 9

Author Comment

by:OBCT
ID: 9919492
Ok, I managed to get my php script working but I had to use $HTTP_GET_VARS.
I tried returning the php result using trace, but it echo's 1 even if my username and password are correct.
Here is my code

stop()
Selection.setFocus(username)
loginBTN.onRelease = function() {
      this._parent.status = "1st stage complete"
      this._parent.myUser = new LoadVars()
      this._parent.myUser.username = _root.username.text
      this._parent.myUser.password = _root.password.text
      this._parent.myUser.onLoad = function() {
            
            trace(this.result);
            if (this.result == "0") {
           gotoAndStop(10)
            }
            else if (this.result == "1") {
           this._parent.status = "Incorrect uesrname or password"
            }
            else if (this.result == "2") {
                  status = "some value"
            }
            else if (this.result == "3") {
                  status = "ip ban"
            }
      };
      this._parent.myUser.sendAndLoad("http://www.dsfsadfsdfasd.com/scripts/login.php", this._parent.myUser, "GET")
}
0
 
LVL 9

Author Comment

by:OBCT
ID: 9919831
Never mind, I got it working :)
Thanks for your help anyway.

Cheers


-OBCT
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 9937978
PAQed, with points refunded (500)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question