Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help... data to -- from php

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
I want to do a small autentification script to practise.

I got 2 input boxes in the flash script , user ans pass.

I added one button that have the following code:

on (release, keyPress "<Enter>") {
if (user != "" && pass != "") {
status="Connecting...please wait...";
loadVariablesNum("login.php", 0, "POST");
}
}

The user input box have Var=user And Instance name userinput.

The pass input box have Var=pass And Instance name passinput.

I also added under this one Dynamic text box having Var=status

The php page looks like this :
login.php


<?
$user=$_POST['user'];
$pass=$_POST['pass'];

if ($user && $pass){
mysql_connect("localhost","root","q99st") or die ("status=Impossible to connect to database.");
mysql_select_db("neo_flashtest") or die ("status=Cannot select base.");
//make query
$query = "SELECT * FROM users WHERE user = '$user' AND pass = '$pass'";
$result = mysql_query( $query ) or die ("status=Query Error.");

$num = mysql_num_rows( $result );
if ($num == 1){
print "status=You are now connected";
} else {
print "status=Bad login or pass";
}
}
?>

If I put a simple echo "status=test"; , withotu any user checkig, the word test appears on my flash script. What may be bad with my code?

(I saw that the variable user doesn't pass from the flash script to the php page....
 
You should use LoadVars() instead of loadVariablesNum(). LoadVars will allow you to send and receive information from the php file without the flash movie ever losing state. It will also allow you to track the progress of the response.

If I undertand your structure correctly it would be something like (assuming your input boxes are on the main timeline, and not part of a movieclip):

Code:
function sendInfo(){
	sendVars = new LoadVars();
	sendVars.user = _root.user;
	sendVars.pass = _root.pass;

	PHPresponse = new LoadVars();
	PHPresponse.onLoad = receiveReply;
	
	if(_root.user != "" && _root.pass != ""){
		sendVars.sendAndLoad("login.php",PHPresponse,"POST");
	}else{
		trace("You must enter a user name and password to continue");
	}
}

function receiveReply(result){
	if(result){
		_root.status = PHPresponse.status;
	}else{
		_root.reply = "There has been an Error";
	}
}

submit.onRelease = function(){
	sendInfo();
}

Hope it helps.


Wow JT that almost looked like you knew what you were doing!
 
I'ma little new to this. My "test" project have only one main frame. When I try to compile it to SWF , I get the following error :

**Error** Scene=Scene 1, layer=content, frame=1:Line 14: Statement must appear within on/onClipEvent handler
function sendInfo(){

**Error** Scene=Scene 1, layer=content, frame=1:Line 29: Statement must appear within on/onClipEvent handler
function receiveReply(result){

**Error** Scene=Scene 1, layer=content, frame=1:Line 36: Statement must appear within on/onClipEvent handler
submit.onRelease = function(){

Total ActionScript Errors: 3 Reported Errors: 3

I put what you gave me in the button's action script.
 
Remove the script from the button.

Create a new layer called "actions" on your main timeline. Add the actionscript to the first frame of that layer.

Also for the example to work correctly the instance name of your submit button needs to be "submit".



Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top