Trying to submit data to php from actionscript

Not working just stays there

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 3080 Views - Last Post: 28 April 2009 - 10:40 AM

#1 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Trying to submit data to php from actionscript

Posted 26 April 2009 - 06:39 AM

So, I'm creating this chat room for this one site. I need help with logging the user in that uses actionscript to pass data to the php file called login.php. All the files are in thee same directory.

When I click on the button of login it doesn't do anything.
However, it does pass login data correctly to the text fields on the flash project.

Here's the php code:

<?php
$Username = $_POST['User'];
$Pass = $_POST['Password'];

echo "User=Paul&Password=houston";
exit;

if(!empty($Username) && !empty($Pass)) {
 
 echo "You are now successfully logged in ".$User."<dt>";
 exit;
 
 }
 else {
 echo "You are not logged in!";
 exit;
 }
 


?>




Here's the login button action script code:

on(press) {
var Request=new LoadVars()
var RequestVars:LoadVars = new LoadVars()
	 
Request.User = User.text
Request.Password = Pass_word.text

RequestVars.sendAndLoad("login.php",Request,"POST");


}




What am I doing wrong - does anyone know?

Thanks for all the help guys! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to submit data to php from actionscript

#2 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 06:50 AM

Hm...
Well, I do know what you want to do... But I donīt quite understand why you are using LoadVars.
I mean, yes, it does send these parameters (user and pass), but they arenīt even tested.
The return of these LoadVars is always "User=Paul&Password=houston".
And... Do you know how to use exit?
So, again, what is not working on there?
Or what do you want to exactly do?
Was This Post Helpful? 0
  • +
  • -

#3 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 07:12 AM

Well, if I wanted to test if the flash fields are filled out then it would display on a page that the user has logged in by testing both to see if any of the flash fields are empty using the POST method in flash.

I thought that LoadVars would pass the data. However, I'm not sure how to send the data to the php file. Would it be GETURL or something? Even that how would I pass what's in the flash variables to the flash?

So, I'm not really sure how to have the php check to see if the variables from flash is valid. if so then do this - if not then display failed. You know?
Was This Post Helpful? 0
  • +
  • -

#4 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 07:23 AM

I used getURL and it seems to work good. However, is there anyway I can use MD5 encryption for the password? Thanks!
Was This Post Helpful? 0
  • +
  • -

#5 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 09:17 AM

Woot, from your post it seems like you want to use the PHP checker only for checking of these are empty :blink: ...

Anyways fixie:
<?php
$username = $_POST['user'];
$pass = $_POST['password'];
if ($username == "MyExampleUser" && $pass == "MyExamplePassword"){
  echo "logged_in=yes";
} else {
  echo "logged_in=no";
}
?>


This is VERY easy, simple etc... and it does the thing you wanted I think... And seriously, donīt use the exit :P.
Now just use the LoadVars...
I think you should see what to do now. The used variable is called "logged_in" and it will be "yes" or "no". :D
And if you want to check if these fields are empty...
Just do
on (release){
if (User.text != "" && Pass_word.text !=""){
// Do the thingies with LoadVars here.
}
}



Finish.
Was This Post Helpful? 0
  • +
  • -

#6 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 09:42 AM

I did what you said. Here what it looks like now.
on(release) {
	if(User.text !="" && Pass_word.text !="") {
		
		
	//this.getURL("login.php?User="+_root.User.text+"&Password="+_root.Pass_word.text+"","","POST");
		   
 var Request=new LoadVars()
 var RequestVars = new LoadVars()
	 
 Request.User = User.text
 Request.Password = Pass_word.text

 RequestVars.sendAndLoad("login.php",Request,"POST");
	if(RequestVars.Logged-In == "Yes") {
	alert.show("You are logged in!","Login Attempt Successful!");
	
	}
	else {
	alert.show("You are not logged in","Login Attempt failed!");
	
	}
	
	}
else {
	alert.show("Username and Password fields can not be empty!","Login Attempt failed!");
	
	 }

}



The alert box isn't even showing up.

I took out the exit's on the php file.
<?php
$Username = $_POST['User'];
$Pass = $_POST['Password'];



if($Username == "Paul" && $Pass = "Monkey")) {
 
 echo "Logged-in=Yes";
 
 
 
 }
 else {
echo "Logged-In=No";



 }
 


?>



I was thinking of passing information to PHP file then if the password and login is correct then goes to the main chat program.
Was This Post Helpful? 0
  • +
  • -

#7 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 11:46 AM

I really like the Flashīs trace function.
After the
RequestVars.sendAndLoad("login.php",Request,"POST");


line, add this:
trace(RequestVars.Logged-In);


It should write something into the output.
Just say if it is "yes", "no" or undefined.
I am getting an idea... But first try this.

EDIT:
I tried these Alert.show, but I think that is the problem... It doesnīt work...
So replace that Alert.show with trace, please.

This post has been edited by Aurel300: 26 April 2009 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 12:07 PM

Oh...
My bad.
It wouldnīt work either...
So, here is your fixie code:
on(release) {
 if (User.text !="" && Pass_word.text !=""){
  var Request=new Object();
  var RequestVars = new LoadVars();
	 
  Request.User = User.text;
  Request.Password = Pass_word.text;

  RequestVars.sendAndLoad("login.php",Request,"POST");
  RequestVars.onload = function(success:Boolean){
   if (success){
	 if(RequestVars.Logged-In == "Yes"){
	  trace("You are logged in!");
	 } else {
	  trace("You are not logged in.");
	 }
   }
  }
 } else {
  trace("Fields must not be empty!");
 }
}



Oh and BTW these traces work only in Flash, not in Flash player, so replace there your code or something... Just not Alert.show(), because it doesnīt work...
Was This Post Helpful? 0
  • +
  • -

#9 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 12:12 PM

It's showing a NaN (Not a Number).

Now it's dsplaying nothing. Here's the PHP code.

<?php
$Username = $_POST['User'];
$Pass = $_POST['Password'];



if($Username == "Paul" && $Pass == "Monkey") {
 
 echo "Logged-In=Yes";
 
 
 
 }
 else {
echo "Logged-In=No";



 }
 



?>


Either I'm doing something wrong or what. I copyed the code and pasted it over the original.

This post has been edited by EvolutionMedia: 26 April 2009 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#10 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 12:18 PM

Did you use my new code I posted later?
Can you please show me the Flash code?

This post has been edited by Aurel300: 26 April 2009 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

#11 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 12:21 PM

View PostAurel300, on 26 Apr, 2009 - 11:18 AM, said:

Did you used my new code I posted later?


Yeah. I will trace that nothing there but won't do anything when it sends and receives.

on(release) {
	if(User.text !="" && Pass_word.text !="") {
		
 var Request=new Object();
  var RequestVars = new LoadVars();
	 
  Request.User = User.text;
  Request.Password = Pass_word.text;

  RequestVars.sendAndLoad("http://www.nxt-ware.net/ChatXP/login.php",Request,"POST");
  RequestVars.onload = function(Success:Boolean){
  if(Success) {
	 if(RequestVars.Logged-In == "Yes"){
	  trace("You are logged in!")
	 } else {
	  trace("You are not logged in.")
	 }
	}
  }
 } else {
  trace("Fields must not be empty!");
 }

}



Was This Post Helpful? 0
  • +
  • -

#12 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 12:47 PM

Again, my bad...
on(release) {
	if(User !="" && Pass_word !="") {
	   
 var Request=new Object();
  var RequestVars = new LoadVars();
	 
  Request.User = User;
  Request.Password = Pass_word;

  RequestVars.sendAndLoad("http://www.nxt-ware.net/ChatXP/login.php",Request,"POST");
  RequestVars.onload = function(Success:Boolean){
  if(Success) {
	 if(RequestVars.Logged-In == "Yes"){
	  trace("You are logged in!")
	 } else {
	  trace("You are not logged in.")
	 }
	}
  }
 } else {
  trace("Fields must not be empty!");
 }
}


Now, on your stage,
your text boxes (User and Pass_word) must be both inputs, both have NO instance name, and in the "var" column "User" / "Pass_word" without quotes.
And again, please write whole (copy and paste) output here.
Was This Post Helpful? 0
  • +
  • -

#13 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 26 April 2009 - 01:15 PM

I went on a site and it kinda helped me but now it gives out a NaN when I try to trace to see if Request.Logged-In.

Flash code:
on(release) {
	if(User.text !="" && Pass_word.text !="") {
		
 var Request:LoadVars=new LoadVars();
	
  Request.User = User.text;
  Request.Password = Pass_word.text;
  Request.sendAndLoad("http://www.nxt-ware.net/ChatXP/login.php",Request,"POST");
  Request.onload = function(Success){

if(Success) {
	 
	 if(Request.Logged-In == "Yes"){
	  trace("You are logged in!")
	 } else {
	  trace("You are not logged in.")
	 }
	}
	else {
		trace("Passing data not successful!");
		
	}
  }
  
 } else {
  trace("Fields must not be empty!");
 }

}




where it says echo "Logged-In=Yes" I put echo "&Logged-In=Yes";

in the php file.

when I would get this from a PHP script - it would mean possibly it has no value behind it or no variable.

Any solutions?
Was This Post Helpful? 0
  • +
  • -

#14 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Trying to submit data to php from actionscript

Posted 27 April 2009 - 11:07 AM

Hm...
I donīt know if you can do:
something.sendAndLoad(blah, something, blah);
I mean, can be the target object the same thing as the one you are sending it from?
Try my part from the code above, I made an object which contains these variables...
And put a trace in the BEGIN of the onload function tracing for example "Blah..."... I donīt know, just to trace if the function was called or not.
Was This Post Helpful? 0
  • +
  • -

#15 EvolutionMedia  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 125
  • Joined: 11-August 08

Re: Trying to submit data to php from actionscript

Posted 27 April 2009 - 01:35 PM

I figured out what was wrong. The reason why it was giving me a NaN because it didn't know what Logged-In was. So I renamed it to LoggedIn and it worked. Now, i'm trying to get a alert box to work when the user doesn't logged in right, instead of the trace function. Any help?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2